[
  {
    "path": ".gitignore",
    "content": "\n# Created by https://www.toptal.com/developers/gitignore/api/laravel,composer\n# Edit at https://www.toptal.com/developers/gitignore?templates=laravel,composer\n\n### Composer ###\ncomposer.phar\n/vendor/\n\n# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control\n# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file\ncomposer.lock\n\n### Laravel ###\nnode_modules/\nnpm-debug.log\nyarn-error.log\n\n# Laravel 4 specific\nbootstrap/compiled.php\napp/storage/\n\n# Laravel 5 & Lumen specific\npublic/storage\npublic/hot\n\n# Laravel 5 & Lumen specific with changed public path\npublic_html/storage\npublic_html/hot\n\nstorage/*.key\n.env\nHomestead.yaml\nHomestead.json\n/.vagrant\n.phpunit.result.cache\n\n# Laravel IDE helper\n*.meta.*\n_ide_*\n\n# End of https://www.toptal.com/developers/gitignore/api/laravel,composer\n\n/.idea\n"
  },
  {
    "path": ".styleci.yml",
    "content": "preset: laravel"
  },
  {
    "path": "changelog.md",
    "content": "# Changelog\n\nAll notable changes to `LaravelTelegramBot` will be documented in this file.\n\n## Version 2.1.0\n\n### Added\n- Support for Laravel 10\n\n### Changed\n- Bump to core version 0.81.0\n\n## Version 2.0.0\n\n### Added\n- Everything\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"php-telegram-bot/laravel\",\n    \"description\": \"Integrates PHP Telegram Bot into Laravel.\",\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Avtandil Kikabidze aka LONGMAN\",\n            \"email\": \"akalongman@gmail.com\",\n            \"homepage\": \"http://longman.me\",\n            \"role\": \"Maintainer, Developer\"\n        },\n        {\n            \"name\": \"Tii\",\n            \"email\": \"mail@tii.one\",\n            \"role\": \"Developer\"\n        }\n    ],\n    \"homepage\": \"https://github.com/php-telegram-bot/laravel\",\n    \"keywords\": [\"laravel\", \"telegram\", \"bot\"],\n    \"require\": {\n        \"illuminate/support\": \"~7|~8|~9|~10|~11|~12\",\n        \"longman/telegram-bot\": \"^0.81\",\n        \"ext-pcntl\": \"*\"\n    },\n    \"require-dev\": {\n        \"phpunit/phpunit\": \"~9.0\",\n        \"symfony/process\": \"^5.3\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"PhpTelegramBot\\\\Laravel\\\\\": \"src/\"\n        }\n    },\n    \"extra\": {\n        \"branch-alias\": {\n            \"dev-main\": \"2.1.x-dev\"\n        },\n        \"laravel\": {\n            \"providers\": [\n              \"PhpTelegramBot\\\\Laravel\\\\TelegramServiceProvider\"\n            ],\n            \"aliases\": {\n                \"CallbackButton\": \"PhpTelegramBot\\\\Laravel\\\\Facades\\\\CallbackButton\",\n                \"Telegram\": \"PhpTelegramBot\\\\Laravel\\\\Facades\\\\Telegram\"\n            }\n        }\n    },\n    \"minimum-stability\": \"dev\",\n    \"prefer-stable\": true,\n    \"config\": {\n        \"allow-plugins\": {\n            \"dealerdirect/phpcodesniffer-composer-installer\": true\n        }\n    }\n}\n"
  },
  {
    "path": "config/telegram.php",
    "content": "<?php\n\nreturn [\n    'bot' => [\n        'api_token' => env('TELEGRAM_API_TOKEN'),\n\n        'username' => env('TELEGRAM_BOT_USERNAME', ''),\n\n        'api_url' => env('TELEGRAM_API_URL'),\n    ],\n\n    'admins' => env('TELEGRAM_ADMINS', '')\n\n];\n"
  },
  {
    "path": "database/migrations/2021_06_14_171118_create_telegram_bot_structure.php",
    "content": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\n\nreturn new class extends Migration {\n    public function up()\n    {\n        DB::unprepared(file_get_contents(__DIR__ . '/sql/structure-0.73.0.sql'));\n    }\n\n    public function down()\n    {\n        //\n    }\n};\n"
  },
  {
    "path": "database/migrations/2022_02_18_175100_update_to_0.75.0.php",
    "content": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\n\nreturn new class extends Migration {\n    public function up()\n    {\n        DB::unprepared(file_get_contents(__DIR__ . '/sql/0.74.0-0.75.0.sql'));\n    }\n\n    public function down()\n    {\n        //\n    }\n};\n"
  },
  {
    "path": "database/migrations/2022_04_24_175700_update_to_0.77.0.php",
    "content": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\n\nreturn new class extends Migration {\n    public function up()\n    {\n        DB::unprepared(file_get_contents(__DIR__ . '/sql/0.76.1-0.77.0.sql'));\n    }\n\n    public function down()\n    {\n        //\n    }\n};\n"
  },
  {
    "path": "database/migrations/2022_10_04_221900_update_to_0.78.0.php",
    "content": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\n\nreturn new class extends Migration {\n    public function up()\n    {\n        DB::unprepared(file_get_contents(__DIR__ . '/sql/0.77.1-0.78.0.sql'));\n    }\n\n    public function down()\n    {\n        //\n    }\n};\n"
  },
  {
    "path": "database/migrations/2022_11_11_130500_update_to_0.80.0.php",
    "content": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Support\\Facades\\DB;\n\nreturn new class extends Migration {\n    public function up()\n    {\n        DB::unprepared(file_get_contents(__DIR__ . '/sql/0.79.0-0.80.0.sql'));\n    }\n\n    public function down()\n    {\n        //\n    }\n};\n"
  },
  {
    "path": "database/migrations/2023_05-07_101600_update_to_0.81.0.php",
    "content": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Support\\Facades\\DB;\n\nreturn new class extends Migration {\n    public function up()\n    {\n        DB::unprepared(file_get_contents(__DIR__ . '/sql/0.80.0-0.81.0.sql'));\n    }\n\n    public function down()\n    {\n        //\n    }\n};\n"
  },
  {
    "path": "database/migrations/sql/0.74.0-0.75.0.sql",
    "content": "CREATE TABLE IF NOT EXISTS `bot_chat_join_request` (\n    `id` BIGINT UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',\n    `chat_id` BIGINT NOT NULL COMMENT 'Chat to which the request was sent',\n    `user_id` BIGINT NOT NULL COMMENT 'User that sent the join request',\n    `date` TIMESTAMP NOT NULL COMMENT 'Date the request was sent in Unix time',\n    `bio` TEXT NULL COMMENT 'Optional. Bio of the user',\n    `invite_link` TEXT NULL COMMENT 'Optional. Chat invite link that was used by the user to send the join request',\n    `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n    PRIMARY KEY (`id`),\n\n    FOREIGN KEY (`chat_id`) REFERENCES `bot_chat` (`id`),\n    FOREIGN KEY (`user_id`) REFERENCES `bot_user` (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nALTER TABLE `bot_telegram_update` ADD COLUMN `chat_join_request_id` BIGINT UNSIGNED NULL COMMENT 'A request to join the chat has been sent';\nALTER TABLE `bot_telegram_update` ADD FOREIGN KEY (`chat_join_request_id`) REFERENCES `bot_chat_join_request` (`id`);\n\nALTER TABLE `bot_message` ADD COLUMN `is_automatic_forward` tinyint(1) DEFAULT 0 COMMENT 'True, if the message is a channel post that was automatically forwarded to the connected discussion group' AFTER `forward_date`;\nALTER TABLE `bot_message` ADD COLUMN `has_protected_content` tinyint(1) DEFAULT 0 COMMENT 'True, if the message can''t be forwarded' AFTER `edit_date`;\n"
  },
  {
    "path": "database/migrations/sql/0.76.1-0.77.0.sql",
    "content": "ALTER TABLE `bot_message` ADD COLUMN `web_app_data` TEXT NULL DEFAULT NULL COMMENT 'Service message: data sent by a Web App' AFTER `voice_chat_participants_invited`;\n\nALTER TABLE `bot_message`\n    CHANGE `voice_chat_scheduled` `video_chat_scheduled` TEXT COMMENT 'Service message: video chat scheduled',\n    CHANGE `voice_chat_started` `video_chat_started` TEXT COMMENT 'Service message: video chat started',\n    CHANGE `voice_chat_ended` `video_chat_ended` TEXT COMMENT 'Service message: video chat ended',\n    CHANGE `voice_chat_participants_invited` `video_chat_participants_invited` TEXT COMMENT 'Service message: new participants invited to a video chat';\n"
  },
  {
    "path": "database/migrations/sql/0.77.1-0.78.0.sql",
    "content": "ALTER TABLE `bot_user` ADD COLUMN `is_premium` tinyint(1) DEFAULT 0 COMMENT 'True, if this user is a Telegram Premium user' AFTER `language_code`;\nALTER TABLE `bot_user` ADD COLUMN `added_to_attachment_menu` tinyint(1) DEFAULT 0 COMMENT 'True, if this user added the bot to the attachment menu' AFTER `is_premium`;\n"
  },
  {
    "path": "database/migrations/sql/0.79.0-0.80.0.sql",
    "content": "ALTER TABLE `bot_message`\n    ADD COLUMN `is_topic_message` TINYINT(1) DEFAULT 0 COMMENT 'True, if the message is sent to a forum topic' AFTER `forward_date`,\n    ADD COLUMN `message_thread_id` BIGINT(20) NULL DEFAULT NULL COMMENT 'Unique identifier of a message thread to which the message belongs; for supergroups only' AFTER `id`,\n    ADD COLUMN `forum_topic_created` TEXT NULL DEFAULT NULL COMMENT 'Service message: forum topic created' AFTER `proximity_alert_triggered`,\n    ADD COLUMN `forum_topic_closed` TEXT NULL DEFAULT NULL COMMENT 'Service message: forum topic closed' AFTER `forum_topic_created`,\n    ADD COLUMN `forum_topic_reopened` TEXT NULL DEFAULT NULL COMMENT 'Service message: forum topic reopened' AFTER `forum_topic_closed`;\n\nALTER TABLE `bot_chat`\n    ADD COLUMN `is_forum` TINYINT(1) DEFAULT 0 COMMENT 'True, if the supergroup chat is a forum (has topics enabled)' AFTER `last_name`;\n"
  },
  {
    "path": "database/migrations/sql/0.80.0-0.81.0.sql",
    "content": "ALTER TABLE `bot_message`\n    ADD COLUMN `has_media_spoiler`            TINYINT(1) DEFAULT 0 COMMENT 'True, if the message media is covered by a spoiler animation' AFTER `caption`,\n    ADD COLUMN `write_access_allowed`         TEXT       DEFAULT NULL COMMENT 'Service message: the user allowed the bot added to the attachment menu to write messages' AFTER `connected_website`,\n    ADD COLUMN `forum_topic_edited`           TEXT       DEFAULT NULL COMMENT 'Service message: forum topic edited' AFTER `forum_topic_created`,\n    ADD COLUMN `general_forum_topic_hidden`   TEXT       DEFAULT NULL COMMENT 'Service message: the General forum topic hidden' AFTER `forum_topic_reopened`,\n    ADD COLUMN `general_forum_topic_unhidden` TEXT       DEFAULT NULL COMMENT 'Service message: the General forum topic unhidden' AFTER `general_forum_topic_hidden`,\n    ADD COLUMN `user_shared`                  TEXT       DEFAULT NULL COMMENT 'Optional. Service message: a user was shared with the bot' AFTER `successful_payment`,\n    ADD COLUMN `chat_shared`                  TEXT       DEFAULT NULL COMMENT 'Optional. Service message: a chat was shared with the bot' AFTER `user_shared`;"
  },
  {
    "path": "database/migrations/sql/structure-0.73.0.sql",
    "content": "CREATE TABLE IF NOT EXISTS bot_user (\n  `id` bigint COMMENT 'Unique identifier for this user or bot',\n  `is_bot` tinyint(1) DEFAULT 0 COMMENT 'True, if this user is a bot',\n  `first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s or bot''s first name',\n  `last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s or bot''s last name',\n  `username` CHAR(191) DEFAULT NULL COMMENT 'User''s or bot''s username',\n  `language_code` CHAR(10) DEFAULT NULL COMMENT 'IETF language tag of the user''s language',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n  `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',\n\n  PRIMARY KEY (`id`),\n  KEY `username` (`username`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_chat (\n  `id` bigint COMMENT 'Unique identifier for this chat',\n  `type` ENUM('private', 'group', 'supergroup', 'channel') NOT NULL COMMENT 'Type of chat, can be either private, group, supergroup or channel',\n  `title` CHAR(255) DEFAULT '' COMMENT 'Title, for supergroups, channels and group chats',\n  `username` CHAR(255) DEFAULT NULL COMMENT 'Username, for private chats, supergroups and channels if available',\n  `first_name` CHAR(255) DEFAULT NULL COMMENT 'First name of the other party in a private chat',\n  `last_name` CHAR(255) DEFAULT NULL COMMENT 'Last name of the other party in a private chat',\n  `all_members_are_administrators` tinyint(1) DEFAULT 0 COMMENT 'True if a all members of this group are admins',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n  `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',\n  `old_id` bigint DEFAULT NULL COMMENT 'Unique chat identifier, this is filled when a group is converted to a supergroup',\n\n  PRIMARY KEY (`id`),\n  KEY `old_id` (`old_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_user_chat (\n  `user_id` bigint COMMENT 'Unique user identifier',\n  `chat_id` bigint COMMENT 'Unique user or chat identifier',\n\n  PRIMARY KEY (`user_id`, `chat_id`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`) ON DELETE CASCADE ON UPDATE CASCADE,\n  FOREIGN KEY (`chat_id`) REFERENCES bot_chat (`id`) ON DELETE CASCADE ON UPDATE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_inline_query (\n  `id` bigint UNSIGNED COMMENT 'Unique identifier for this query',\n  `user_id` bigint NULL COMMENT 'Unique user identifier',\n  `location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location of the user',\n  `query` TEXT NOT NULL COMMENT 'Text of the query',\n  `offset` CHAR(255) NULL DEFAULT NULL COMMENT 'Offset of the result',\n  `chat_type` CHAR(255) NULL DEFAULT NULL COMMENT 'Optional. Type of the chat, from which the inline query was sent.',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`),\n  KEY `user_id` (`user_id`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_chosen_inline_result (\n  `id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',\n  `result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'The unique identifier for the result that was chosen',\n  `user_id` bigint NULL COMMENT 'The user that chose the result',\n  `location` CHAR(255) NULL DEFAULT NULL COMMENT 'Sender location, only for bots that require user location',\n  `inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the sent inline message',\n  `query` TEXT NOT NULL COMMENT 'The query that was used to obtain the result',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`),\n  KEY `user_id` (`user_id`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_message (\n  `chat_id` bigint COMMENT 'Unique chat identifier',\n  `sender_chat_id` bigint COMMENT 'Sender of the message, sent on behalf of a chat',\n  `id` bigint UNSIGNED COMMENT 'Unique message identifier',\n  `user_id` bigint NULL COMMENT 'Unique user identifier',\n  `date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was sent in timestamp format',\n  `forward_from` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, sender of the original message',\n  `forward_from_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier, chat the original message belongs to',\n  `forward_from_message_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier of the original message in the channel',\n  `forward_signature` TEXT NULL DEFAULT NULL COMMENT 'For messages forwarded from channels, signature of the post author if present',\n  `forward_sender_name` TEXT NULL DEFAULT NULL COMMENT 'Sender''s name for messages forwarded from users who disallow adding a link to their account in forwarded messages',\n  `forward_date` timestamp NULL DEFAULT NULL COMMENT 'date the original message was sent in timestamp format',\n  `reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',\n  `reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message that this message is reply to',\n  `via_bot` bigint NULL DEFAULT NULL COMMENT 'Optional. Bot through which the message was sent',\n  `edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was last edited in Unix time',\n  `media_group_id` TEXT COMMENT 'The unique identifier of a media message group this message belongs to',\n  `author_signature` TEXT COMMENT 'Signature of the post author for messages in channels',\n  `text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8mb4',\n  `entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',\n  `caption_entities` TEXT COMMENT 'For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption',\n  `audio` TEXT COMMENT 'Audio object. Message is an audio file, information about the file',\n  `document` TEXT COMMENT 'Document object. Message is a general file, information about the file',\n  `animation` TEXT COMMENT 'Message is an animation, information about the animation',\n  `game` TEXT COMMENT 'Game object. Message is a game, information about the game',\n  `photo` TEXT COMMENT 'Array of PhotoSize objects. Message is a photo, available sizes of the photo',\n  `sticker` TEXT COMMENT 'Sticker object. Message is a sticker, information about the sticker',\n  `video` TEXT COMMENT 'Video object. Message is a video, information about the video',\n  `voice` TEXT COMMENT 'Voice Object. Message is a Voice, information about the Voice',\n  `video_note` TEXT COMMENT 'VoiceNote Object. Message is a Video Note, information about the Video Note',\n  `caption` TEXT COMMENT  'For message with caption, the actual UTF-8 text of the caption',\n  `contact` TEXT COMMENT 'Contact object. Message is a shared contact, information about the contact',\n  `location` TEXT COMMENT 'Location object. Message is a shared location, information about the location',\n  `venue` TEXT COMMENT 'Venue object. Message is a Venue, information about the Venue',\n  `poll` TEXT COMMENT 'Poll object. Message is a native poll, information about the poll',\n  `dice` TEXT COMMENT 'Message is a dice with random value from 1 to 6',\n  `new_chat_members` TEXT COMMENT 'List of unique user identifiers, new member(s) were added to the group, information about them (one of these members may be the bot itself)',\n  `left_chat_member` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, a member was removed from the group, information about them (this member may be the bot itself)',\n  `new_chat_title` CHAR(255) DEFAULT NULL COMMENT 'A chat title was changed to this value',\n  `new_chat_photo` TEXT COMMENT 'Array of PhotoSize objects. A chat photo was change to this value',\n  `delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the chat photo was deleted',\n  `group_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group has been created',\n  `supergroup_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the supergroup has been created',\n  `channel_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the channel chat has been created',\n  `message_auto_delete_timer_changed` TEXT COMMENT 'MessageAutoDeleteTimerChanged object. Message is a service message: auto-delete timer settings changed in the chat',\n  `migrate_to_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate to chat identifier. The group has been migrated to a supergroup with the specified identifier',\n  `migrate_from_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate from chat identifier. The supergroup has been migrated from a group with the specified identifier',\n  `pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned',\n  `invoice` TEXT NULL COMMENT 'Message is an invoice for a payment, information about the invoice',\n  `successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment',\n  `connected_website` TEXT NULL COMMENT 'The domain name of the website on which the user has logged in.',\n  `passport_data` TEXT NULL COMMENT 'Telegram Passport data',\n  `proximity_alert_triggered` TEXT NULL COMMENT 'Service message. A user in the chat triggered another user''s proximity alert while sharing Live Location.',\n  `voice_chat_scheduled` TEXT COMMENT 'VoiceChatScheduled object. Message is a service message: voice chat scheduled',\n  `voice_chat_started` TEXT COMMENT 'VoiceChatStarted object. Message is a service message: voice chat started',\n  `voice_chat_ended` TEXT COMMENT 'VoiceChatEnded object. Message is a service message: voice chat ended',\n  `voice_chat_participants_invited` TEXT COMMENT 'VoiceChatParticipantsInvited object. Message is a service message: new participants invited to a voice chat',\n  `reply_markup` TEXT NULL COMMENT 'Inline keyboard attached to the message',\n\n  PRIMARY KEY (`chat_id`, `id`),\n  KEY `user_id` (`user_id`),\n  KEY `forward_from` (`forward_from`),\n  KEY `forward_from_chat` (`forward_from_chat`),\n  KEY `reply_to_chat` (`reply_to_chat`),\n  KEY `reply_to_message` (`reply_to_message`),\n  KEY `via_bot` (`via_bot`),\n  KEY `left_chat_member` (`left_chat_member`),\n  KEY `migrate_from_chat_id` (`migrate_from_chat_id`),\n  KEY `migrate_to_chat_id` (`migrate_to_chat_id`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`),\n  FOREIGN KEY (`chat_id`) REFERENCES bot_chat (`id`),\n  FOREIGN KEY (`forward_from`) REFERENCES bot_user (`id`),\n  FOREIGN KEY (`forward_from_chat`) REFERENCES bot_chat (`id`),\n  FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES bot_message (`chat_id`, `id`),\n  FOREIGN KEY (`via_bot`) REFERENCES bot_user (`id`),\n  FOREIGN KEY (`left_chat_member`) REFERENCES bot_user (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_edited_message (\n  `id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',\n  `chat_id` bigint COMMENT 'Unique chat identifier',\n  `message_id` bigint UNSIGNED COMMENT 'Unique message identifier',\n  `user_id` bigint NULL COMMENT 'Unique user identifier',\n  `edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was edited in timestamp format',\n  `text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8',\n  `entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',\n  `caption` TEXT COMMENT  'For message with caption, the actual UTF-8 text of the caption',\n\n  PRIMARY KEY (`id`),\n  KEY `chat_id` (`chat_id`),\n  KEY `message_id` (`message_id`),\n  KEY `user_id` (`user_id`),\n\n  FOREIGN KEY (`chat_id`) REFERENCES bot_chat (`id`),\n  FOREIGN KEY (`chat_id`, `message_id`) REFERENCES bot_message (`chat_id`, `id`),\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_callback_query (\n  `id` bigint UNSIGNED COMMENT 'Unique identifier for this query',\n  `user_id` bigint NULL COMMENT 'Unique user identifier',\n  `chat_id` bigint NULL COMMENT 'Unique chat identifier',\n  `message_id` bigint UNSIGNED COMMENT 'Unique message identifier',\n  `inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the message sent via the bot in inline mode, that originated the query',\n  `chat_instance` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent',\n  `data` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Data associated with the callback button',\n  `game_short_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Short name of a Game to be returned, serves as the unique identifier for the game',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`),\n  KEY `user_id` (`user_id`),\n  KEY `chat_id` (`chat_id`),\n  KEY `message_id` (`message_id`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`),\n  FOREIGN KEY (`chat_id`, `message_id`) REFERENCES bot_message (`chat_id`, `id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_shipping_query (\n  `id` bigint UNSIGNED COMMENT 'Unique query identifier',\n  `user_id` bigint COMMENT 'User who sent the query',\n  `invoice_payload` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Bot specified invoice payload',\n  `shipping_address` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User specified shipping address',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`),\n  KEY `user_id` (`user_id`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_pre_checkout_query (\n  `id` bigint UNSIGNED COMMENT 'Unique query identifier',\n  `user_id` bigint COMMENT 'User who sent the query',\n  `currency` CHAR(3) COMMENT 'Three-letter ISO 4217 currency code',\n  `total_amount` bigint COMMENT 'Total price in the smallest units of the currency',\n  `invoice_payload` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Bot specified invoice payload',\n  `shipping_option_id` CHAR(255) NULL COMMENT 'Identifier of the shipping option chosen by the user',\n  `order_info` TEXT NULL COMMENT 'Order info provided by the user',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`),\n  KEY `user_id` (`user_id`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_poll (\n  `id` bigint UNSIGNED COMMENT 'Unique poll identifier',\n  `question` text NOT NULL COMMENT 'Poll question',\n  `options` text NOT NULL COMMENT 'List of poll options',\n  `total_voter_count` int UNSIGNED COMMENT 'Total number of users that voted in the poll',\n  `is_closed` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll is closed',\n  `is_anonymous` tinyint(1) DEFAULT 1 COMMENT 'True, if the poll is anonymous',\n  `type` char(255) COMMENT 'Poll type, currently can be “regular” or “quiz”',\n  `allows_multiple_answers` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll allows multiple answers',\n  `correct_option_id` int UNSIGNED COMMENT '0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot.',\n  `explanation` varchar(255) DEFAULT NULL COMMENT 'Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters',\n  `explanation_entities` text DEFAULT NULL COMMENT 'Special entities like usernames, URLs, bot commands, etc. that appear in the explanation',\n  `open_period` int UNSIGNED DEFAULT NULL COMMENT 'Amount of time in seconds the poll will be active after creation',\n  `close_date` timestamp NULL DEFAULT NULL COMMENT 'Point in time (Unix timestamp) when the poll will be automatically closed',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_poll_answer (\n  `poll_id` bigint UNSIGNED COMMENT 'Unique poll identifier',\n  `user_id` bigint NOT NULL COMMENT 'The user, who changed the answer to the poll',\n  `option_ids` text NOT NULL COMMENT '0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote.',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`poll_id`, `user_id`),\n  FOREIGN KEY (`poll_id`) REFERENCES bot_poll (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_chat_member_updated (\n  `id` BIGINT UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',\n  `chat_id` BIGINT NOT NULL COMMENT 'Chat the user belongs to',\n  `user_id` BIGINT NOT NULL COMMENT 'Performer of the action, which resulted in the change',\n  `date` TIMESTAMP NOT NULL COMMENT 'Date the change was done in Unix time',\n  `old_chat_member` TEXT NOT NULL COMMENT 'Previous information about the chat member',\n  `new_chat_member` TEXT NOT NULL COMMENT 'New information about the chat member',\n  `invite_link` TEXT NULL COMMENT 'Chat invite link, which was used by the user to join the chat; for joining by invite link events only',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`),\n  FOREIGN KEY (`chat_id`) REFERENCES bot_chat (`id`),\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_telegram_update (\n  `id` bigint UNSIGNED COMMENT 'Update''s unique identifier',\n  `chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',\n  `message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming message of any kind - text, photo, sticker, etc.',\n  `edited_message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New version of a message that is known to the bot and was edited',\n  `channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming channel post of any kind - text, photo, sticker, etc.',\n  `edited_channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New version of a channel post that is known to the bot and was edited',\n  `inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming inline query',\n  `chosen_inline_result_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The result of an inline query that was chosen by a user and sent to their chat partner',\n  `callback_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming callback query',\n  `shipping_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming shipping query. Only for invoices with flexible price',\n  `pre_checkout_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming pre-checkout query. Contains full information about checkout',\n  `poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New poll state. Bots receive only updates about polls, which are sent or stopped by the bot',\n  `poll_answer_poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.',\n  `my_chat_member_updated_id` BIGINT UNSIGNED NULL COMMENT 'The bot''s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.',\n  `chat_member_updated_id` BIGINT UNSIGNED NULL COMMENT 'A chat member''s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates to receive these updates.',\n\n  PRIMARY KEY (`id`),\n  KEY `message_id` (`message_id`),\n  KEY `chat_message_id` (`chat_id`, `message_id`),\n  KEY `edited_message_id` (`edited_message_id`),\n  KEY `channel_post_id` (`channel_post_id`),\n  KEY `edited_channel_post_id` (`edited_channel_post_id`),\n  KEY `inline_query_id` (`inline_query_id`),\n  KEY `chosen_inline_result_id` (`chosen_inline_result_id`),\n  KEY `callback_query_id` (`callback_query_id`),\n  KEY `shipping_query_id` (`shipping_query_id`),\n  KEY `pre_checkout_query_id` (`pre_checkout_query_id`),\n  KEY `poll_id` (`poll_id`),\n  KEY `poll_answer_poll_id` (`poll_answer_poll_id`),\n  KEY `my_chat_member_updated_id` (`my_chat_member_updated_id`),\n  KEY `chat_member_updated_id` (`chat_member_updated_id`),\n\n  FOREIGN KEY (`chat_id`, `message_id`) REFERENCES bot_message (`chat_id`, `id`),\n  FOREIGN KEY (`edited_message_id`) REFERENCES bot_edited_message (`id`),\n  FOREIGN KEY (`chat_id`, `channel_post_id`) REFERENCES bot_message (`chat_id`, `id`),\n  FOREIGN KEY (`edited_channel_post_id`) REFERENCES bot_edited_message (`id`),\n  FOREIGN KEY (`inline_query_id`) REFERENCES bot_inline_query (`id`),\n  FOREIGN KEY (`chosen_inline_result_id`) REFERENCES bot_chosen_inline_result (`id`),\n  FOREIGN KEY (`callback_query_id`) REFERENCES bot_callback_query (`id`),\n  FOREIGN KEY (`shipping_query_id`) REFERENCES bot_shipping_query (`id`),\n  FOREIGN KEY (`pre_checkout_query_id`) REFERENCES bot_pre_checkout_query (`id`),\n  FOREIGN KEY (`poll_id`) REFERENCES bot_poll (`id`),\n  FOREIGN KEY (`poll_answer_poll_id`) REFERENCES bot_poll_answer (`poll_id`),\n  FOREIGN KEY (`my_chat_member_updated_id`) REFERENCES bot_chat_member_updated (`id`),\n  FOREIGN KEY (`chat_member_updated_id`) REFERENCES bot_chat_member_updated (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_conversation (\n  `id` bigint(20) unsigned AUTO_INCREMENT COMMENT 'Unique identifier for this entry',\n  `user_id` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier',\n  `chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique user or chat identifier',\n  `status` ENUM('active', 'cancelled', 'stopped') NOT NULL DEFAULT 'active' COMMENT 'Conversation state',\n  `command` varchar(160) DEFAULT '' COMMENT 'Default command to execute',\n  `notes` text DEFAULT NULL COMMENT 'Data stored from command',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n  `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',\n\n  PRIMARY KEY (`id`),\n  KEY `user_id` (`user_id`),\n  KEY `chat_id` (`chat_id`),\n  KEY `status` (`status`),\n\n  FOREIGN KEY (`user_id`) REFERENCES bot_user (`id`),\n  FOREIGN KEY (`chat_id`) REFERENCES bot_chat (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n\nCREATE TABLE IF NOT EXISTS bot_request_limiter (\n  `id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',\n  `chat_id` char(255) NULL DEFAULT NULL COMMENT 'Unique chat identifier',\n  `inline_message_id` char(255) NULL DEFAULT NULL COMMENT 'Identifier of the sent inline message',\n  `method` char(255) DEFAULT NULL COMMENT 'Request method',\n  `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',\n\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;\n"
  },
  {
    "path": "license.md",
    "content": "# The license\n\nMIT License\n\nCopyright (c) 2022 [PHP Telegram Bot](https://github.com/php-telegram-bot)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "phpunit.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit bootstrap=\"vendor/autoload.php\"\n         backupGlobals=\"false\"\n         backupStaticAttributes=\"false\"\n         colors=\"true\"\n         verbose=\"true\"\n         convertErrorsToExceptions=\"true\"\n         convertNoticesToExceptions=\"true\"\n         convertWarningsToExceptions=\"true\"\n         processIsolation=\"false\"\n         stopOnFailure=\"false\">\n    <testsuites>\n        <testsuite name=\"Package\">\n            <directory suffix=\".php\">./tests/</directory>\n        </testsuite>\n    </testsuites>\n    <filter>\n        <whitelist>\n            <directory>src/</directory>\n        </whitelist>\n    </filter>\n</phpunit>\n"
  },
  {
    "path": "readme.md",
    "content": "# LaravelTelegramBot\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Total Downloads][ico-downloads]][link-downloads]\n\n## Installation\n\nInstall this package through Composer. Run this command in your project's terminal:\n\n``` bash\ncomposer require php-telegram-bot/laravel\n```\n\nExecute the following command to publish the folder structure to your Laravel application:\n```bash\nphp artisan telegram:publish\n```\nThis also includes a dummy `/start` command to give you a quick start.\n\nSince we're using the database part of php-telegram-bot you should run the migrations so the database schema gets installed:\n```bash\nphp artisan migrate\n```\n\nAnd add the following lines to your .env file:\n```dotenv\nTELEGRAM_API_TOKEN=\nTELEGRAM_BOT_USERNAME=\nTELEGRAM_API_URL=\nTELEGRAM_ADMINS=\n```\n\n`TELEGRAM_API_TOKEN` and `TELEGRAM_BOT_USERNAME` should be filled with the corresponding data from [@BotFather](https://t.me/BotFather)\n\n`TELEGRAM_API_URL` is optional and can be filled with the URL to your  [custom Bot API Server](https://core.telegram.org/bots/api#using-a-local-bot-api-server) if you want to use one.\n\n`TELEGRAM_ADMINS` is optional and a comma-separated list of Telegram User IDs that gets passed to the `enableAdmins` command of php-telegram-bot to enable admin commands for those users.\n\nAfter that you can run `php artisan telegram:set-webhook` if your development server is reachable from the outside or you're using a custom bot api server. \n\nOr `php artisan telegram:fetch` to start fetching your updates via polling.\n\n⚠️ Be aware that you have to cancel and restart the `telegram:fetch` command, if you change your code.\n\n## Usage\nFor further basic configuration of this Laravel package you do not need to create any configuration files.\n\nArtisan terminal commands for the Webhook usage (remember, that you need an HTTPS server for it):\n``` bash\n# Use this method to specify a url and receive incoming updates via an outgoing webhook\nphp artisan telegram:set-webhook\n# List of available options: \n# --d|drop-pending-updates : Drop all pending updates\n# --a|all-update-types : Explicitly allow all updates (including \"chat_member\")\n# --allowed-updates= : Define allowed updates (comma-seperated)\n\n# Use this method to remove webhook integration if you decide to switch back to getUpdates\nphp artisan telegram:delete-webhook\n# List of available options:\n# --d|drop-pending-updates : Pass to drop all pending updates\n```\nArtisan terminal commands for the Telegram getUpdates method:\n``` bash\n# Fetches Telegram updates periodically\nphp artisan telegram:fetch \n# List of available options:\n# --a|all-update-types : Explicitly allow all updates (including \"chat_member\")\n# --allowed-updates= : Define allowed updates (comma-seperated)\n```\nArtisan terminal command for Telegram Server logging out:\n``` bash\n# Sends a logout to the currently registered Telegram Server\nphp artisan telegram:logout\n```\nArtisan terminal command for closing Telegram Server:\n``` bash\n# Sends a close to the currently registered Telegram Server\nphp artisan telegram:close\n```\nArtisan terminal command for publishing Telegram command folder structure in your project:\n``` bash\n# Publishes folder structure for Telegram Commands\n# Default StartCommand class will be created\nphp artisan telegram:publish\n```\nArtisan terminal command for creating new Telegram command class in your project:\n``` bash\n# Create a new Telegram Bot Command class\n# e.g. php artisan make:telegram-command Menu --> will make User command class MenuCommand \n# e.g. php artisan make:telegram-command Genericmessage --system --> will make System command class GenericmessageCommand\nphp artisan make:telegram-command\n# List of available options:\n# name : Name of the Telegram Command\n# --a|admin : Generate a AdminCommand\n# --s|system : Generate a SystemCommand\n# Without admin or system option default User command will be created\n```\n\n\n\n## Credits\n\n- [Avtandil Kikabidze aka LONGMAN](https://github.com/akalongman)\n- [TiiFuchs](https://github.com/TiiFuchs)\n- [All Contributors][link-contributors]\n\n## License\n\nPlease see the [license file](license.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/php-telegram-bot/laravel.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/php-telegram-bot/laravel.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/php-telegram-bot/laravel\n[link-downloads]: https://packagist.org/packages/php-telegram-bot/laravel\n[link-contributors]: https://github.com/php-telegram-bot/laravel/contributors\n"
  },
  {
    "path": "routes/telegram.php",
    "content": "<?php\n\nRoute::post('/api/telegram/webhook/{token}', static function (\\Longman\\TelegramBot\\Telegram $bot, $token) {\n    if ($token != config('telegram.bot.api_token')) {\n        abort(400);\n    }\n\n    $bot->handle();\n})->middleware('telegram.network')->name('telegram.webhook');\n"
  },
  {
    "path": "src/Console/Commands/GeneratorCommand.php",
    "content": "<?php\n\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\n\nuse Illuminate\\Console\\Command;\n\nabstract class GeneratorCommand extends Command\n{\n\n    protected function publish(string $source, string $destination, array $replacements = [], bool $overwrite = false) : bool\n    {\n        if (file_exists($destination) && ! $overwrite) {\n            $basename = basename($destination);\n            $this->error(\"{$basename} already exists!\");\n            return false;\n        }\n\n        $content = file_get_contents($source);\n        $content = $this->replacePlaceholder($content, $replacements);\n        file_put_contents($destination, $content);\n\n        return true;\n    }\n\n    protected function replacePlaceholder(string $content, array $replacements): string\n    {\n        foreach ($replacements as $from => $to) {\n            $content = str_replace($from, $to, $content);\n        }\n\n        return $content;\n    }\n\n    protected function getRootNamespace(): string\n    {\n        return rtrim($this->laravel->getNamespace(), '\\\\');\n    }\n\n}\n"
  },
  {
    "path": "src/Console/Commands/MakeTelegramCommand.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\nuse Illuminate\\Support\\Str;\n\nclass MakeTelegramCommand extends GeneratorCommand\n{\n    protected $signature = 'make:telegram-command\n                            {name : Name of the Telegram Command}\n                            {--a|admin : Generate a AdminCommand}\n                            {--s|system : Generate a SystemCommand}';\n\n    protected $description = 'Create a new Telegram Bot Command class';\n\n    /*\n     * DummyNamespace\n     * DummyParent\n     * DummyClass\n     * {{name}}\n     */\n\n    public function handle()\n    {\n        $name = $this->argument('name'); // start\n\n        if (Str::endsWith($name, ['Command', 'command'])) {\n            $name = (string) Str::of($name)->substr(0, -7)->lower();\n        } else {\n            $name = Str::lower($name);\n        }\n\n        $class = Str::studly($name) . 'Command';\n\n        $success = $this->publish(\n            __DIR__ . '/stubs/telegram-command.stub',\n            app_path(\"Telegram/Commands/{$class}.php\"),\n            [\n                'DummyNamespace' => $this->getRootNamespace(),\n                'DummyParent'    => $this->getParentClassName(),\n                'DummyClass'     => $class,\n                '{{name}}'       => $name\n            ]\n        );\n\n        if ($success) {\n            $this->info('Telegram Command created successfully');\n        }\n    }\n\n    protected function getParentClassName()\n    {\n        if ($this->option('admin')) {\n            return 'AdminCommand';\n        }\n\n        if ($this->option('system')) {\n            return 'SystemCommand';\n        }\n\n        return 'UserCommand';\n    }\n}\n"
  },
  {
    "path": "src/Console/Commands/TelegramCloseCommand.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\nuse Illuminate\\Console\\Command;\nuse Longman\\TelegramBot\\Request;\nuse Longman\\TelegramBot\\Telegram;\n\nclass TelegramCloseCommand extends Command\n{\n    protected $signature = 'telegram:close';\n\n    protected $description = 'Sends a close to the currently registered Telegram Server';\n\n    public function handle(Telegram $bot)\n    {\n        $response = Request::close();\n\n        if (! $response->isOk()) {\n            $this->error($response->getDescription());\n        }\n\n        $this->info($response->getDescription());\n    }\n}\n"
  },
  {
    "path": "src/Console/Commands/TelegramDeleteWebhookCommand.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\nuse Illuminate\\Console\\Command;\nuse Longman\\TelegramBot\\Request;\nuse Longman\\TelegramBot\\Telegram;\n\nclass TelegramDeleteWebhookCommand extends Command\n{\n    protected $signature = 'telegram:delete-webhook\n                            {--d|drop-pending-updates : Pass to drop all pending updates}';\n\n    protected $description = 'Use this method to remove webhook integration if you decide to switch back to getUpdates';\n\n    public function handle(Telegram $bot)\n    {\n        $options = [];\n        if ($this->option('drop-pending-updates')) {\n            $options['drop_pending_updates'] = true;\n        }\n\n        $response = Request::deleteWebhook($options);\n\n        if (! $response->isOk()) {\n            $this->error($response->getDescription());\n        }\n\n        $this->info($response->getDescription());\n    }\n}\n"
  },
  {
    "path": "src/Console/Commands/TelegramFetchCommand.php",
    "content": "<?php\n\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\n\nuse Illuminate\\Console\\Command;\nuse Illuminate\\Support\\Str;\nuse Longman\\TelegramBot\\Entities\\Update;\nuse Longman\\TelegramBot\\Exception\\TelegramException;\nuse Longman\\TelegramBot\\Telegram;\nuse Symfony\\Component\\Console\\Command\\SignalableCommandInterface;\n\nclass TelegramFetchCommand extends Command implements SignalableCommandInterface\n{\n\n    protected $signature = 'telegram:fetch\n                            {--a|all-update-types : Explicitly allow all updates (including \"chat_member\")}\n                            {--allowed-updates= : Define allowed updates (comma-seperated)}';\n\n    protected $description = 'Fetches Telegram updates periodically';\n\n    protected bool $shallExit = false;\n\n    protected ?int $childPid = null;\n\n    public function handle(Telegram $bot)\n    {\n        $this->callSilent('telegram:delete-webhook');\n\n        $options = [\n            'timeout' => 30\n        ];\n\n        // allowed_updates\n        if ($this->option('all-update-types')) {\n            $options['allowed_updates'] = Update::getUpdateTypes();\n        } elseif ($allowedUpdates = $this->option('allowed-updates')) {\n            $options['allowed_updates'] = Str::of($allowedUpdates)->explode(',');\n        }\n\n        $this->info(\"Start fetching updates...\\n<comment>(Exit with Ctrl + C)</comment>\");\n\n        if ($this->childPid = pcntl_fork()) {\n            // Parent process\n\n            while (true) {\n\n                if ($this->shallExit) {\n                    exec('kill -9 ' . $this->childPid);\n                    break;\n                }\n\n            }\n\n        } else {\n            // Child process\n\n            while (true) {\n\n                $response = rescue(fn() => $bot->handleGetUpdates($options));\n\n                if ($response !== null && ! $response->isOk()) {\n                    $this->error($response->getDescription());\n                }\n\n            }\n\n        }\n    }\n\n    public function getSubscribedSignals(): array\n    {\n        return [SIGINT];\n    }\n\n    public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false\n    {\n        $this->shallExit = true;\n    }\n}\n"
  },
  {
    "path": "src/Console/Commands/TelegramLogoutCommand.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\nuse Illuminate\\Console\\Command;\nuse Longman\\TelegramBot\\Request;\nuse Longman\\TelegramBot\\Telegram;\n\nclass TelegramLogoutCommand extends Command\n{\n    protected $signature = 'telegram:logout';\n\n    protected $description = 'Sends a logout to the currently registered Telegram Server';\n\n    public function handle(Telegram $bot)\n    {\n        $response = Request::logOut();\n\n        if (! $response->isOk()) {\n            $this->error($response->getDescription());\n        }\n\n        $this->info($response->getDescription());\n    }\n}\n"
  },
  {
    "path": "src/Console/Commands/TelegramPublishCommand.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\nuse Illuminate\\Filesystem\\Filesystem;\n\nclass TelegramPublishCommand extends GeneratorCommand\n{\n    protected $signature = 'telegram:publish';\n\n    protected $description = 'Publishes folder structure for Telegram Commands';\n\n    public function handle()\n    {\n        (new Filesystem())->ensureDirectoryExists(app_path('Telegram/Commands'));\n        $success = $this->publish(\n            __DIR__ . '/stubs/example-start-command.stub',\n            app_path('Telegram/Commands/StartCommand.php'),\n            [\n                'DummyRootNamespace' => $this->getRootNamespace(),\n            ]\n        );\n\n        if ($success) {\n            $this->info('Publishing complete.');\n        }\n    }\n\n}\n"
  },
  {
    "path": "src/Console/Commands/TelegramSetWebhookCommand.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Console\\Commands;\n\nuse Illuminate\\Console\\Command;\nuse Illuminate\\Support\\Str;\nuse Longman\\TelegramBot\\Entities\\Update;\nuse Longman\\TelegramBot\\Telegram;\n\nclass TelegramSetWebhookCommand extends Command\n{\n    protected $signature = 'telegram:set-webhook\n                            {hostname? : Hostname to set}\n                            {--d|drop-pending-updates : Drop all pending updates}\n                            {--a|all-update-types : Explicitly allow all updates (including \"chat_member\")}\n                            {--allowed-updates= : Define allowed updates (comma-seperated)}';\n\n    protected $description = 'Use this method to specify a url and receive incoming updates via an outgoing webhook';\n\n    public function handle(Telegram $bot)\n    {\n        $hostname = $this->argument('hostname');\n        if (! $hostname) {\n            $hostname = $this->ask('Which hostname do you like to set?', config('app.url'));\n        }\n\n        if (! Str::of($hostname)->startsWith('http')) {\n            $schema = match (app()->environment()) {\n                'local' => 'http',\n                default => 'https'\n            };\n            $hostname = \"{$schema}://{$hostname}\";\n        }\n\n        $url = $hostname . route('telegram.webhook', [\n                'token' => config('telegram.bot.api_token')\n            ], false);\n\n        $options = [];\n        if ($this->option('drop-pending-updates')) {\n            $options['drop_pending_updates'] = true;\n        }\n\n        if ($this->option('all-update-types')) {\n            $options['allowed_updates'] = Update::getUpdateTypes();\n        } elseif ($allowedUpdates = $this->option('allowed-updates')) {\n            $options['allowed_updates'] = Str::of($allowedUpdates)->explode(',');\n        }\n\n        $response = $bot->setWebhook($url, $options);\n\n        if (! $response->isOk()) {\n            $this->error($response->getDescription());\n        }\n\n        $this->info(\"Telegram Webhook set to <comment>{$url}</comment>\");\n    }\n}\n"
  },
  {
    "path": "src/Console/Commands/stubs/example-start-command.stub",
    "content": "<?php\n\n\nnamespace DummyRootNamespace\\Telegram\\Commands;\n\n\nuse Longman\\TelegramBot\\Commands\\UserCommand;\nuse Longman\\TelegramBot\\Entities\\ServerResponse;\nuse Longman\\TelegramBot\\Exception\\TelegramException;\n\nclass StartCommand extends UserCommand\n{\n\n    /** @var string Command name */\n    protected $name = 'start';\n    /** @var string Command description */\n    protected $description = 'Start';\n    /** @var string Usage description */\n    protected $usage = '/start';\n    /** @var string Version */\n    protected $version = '1.0.0';\n\n    public function execute(): ServerResponse\n    {\n        return $this->replyToChat('Hello world! 👋');\n    }\n\n}\n"
  },
  {
    "path": "src/Console/Commands/stubs/telegram-command.stub",
    "content": "<?php\n\n\nnamespace DummyNamespace\\Telegram\\Commands;\n\n\nuse Longman\\TelegramBot\\Commands\\DummyParent;\nuse Longman\\TelegramBot\\Entities\\ServerResponse;\nuse Longman\\TelegramBot\\Exception\\TelegramException;\n\nclass DummyClass extends DummyParent\n{\n\n    /** @var string Command name */\n    protected $name = '{{name}}';\n    /** @var string Command description */\n    protected $description = '';\n    /** @var string Usage description */\n    protected $usage = '/{{name}}';\n    /** @var string Version */\n    protected $version = '1.0.0';\n\n    public function execute(): ServerResponse\n    {\n\n    }\n\n}\n"
  },
  {
    "path": "src/Facades/CallbackButton.php",
    "content": "<?php\n\n\nnamespace PhpTelegramBot\\Laravel\\Facades;\n\n\nuse Illuminate\\Support\\Facades\\Facade;\n\nclass CallbackButton extends Facade\n{\n    protected static function getFacadeAccessor()\n    {\n        return \\PhpTelegramBot\\Laravel\\Factories\\CallbackButton::class;\n    }\n}\n"
  },
  {
    "path": "src/Facades/Telegram.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Facades;\n\nuse Illuminate\\Support\\Facades\\Facade;\nuse PhpTelegramBot\\Laravel\\LaravelTelegramBot;\n\nclass Telegram extends Facade\n{\n    protected static function getFacadeAccessor()\n    {\n        return LaravelTelegramBot::class;\n    }\n}"
  },
  {
    "path": "src/Factories/CallbackButton.php",
    "content": "<?php\n\n\nnamespace PhpTelegramBot\\Laravel\\Factories;\n\n\nuse Illuminate\\Support\\Facades\\Cache;\nuse Illuminate\\Support\\Str;\nuse Longman\\TelegramBot\\Entities\\InlineKeyboardButton;\n\nclass CallbackButton\n{\n\n    protected string $className;\n    protected array $data;\n\n    public function __call(string $name, array $arguments): self\n    {\n        // ->withXxxxx($value)\n        if (Str::startsWith($name, 'with')) {\n            $key = (string) Str::of($name)->after('with')->snake();\n            $value = head($arguments);\n\n            return $this->with($key, $value);\n        }\n\n        throw new \\BadMethodCallException(\"Call to undefined method CallbackButton::{$name}()\");\n    }\n\n    public function with(string $key, mixed $value): self\n    {\n        $this->data[$key] = $value;\n        return $this;\n    }\n\n    public function new(): self\n    {\n        return clone $this;\n    }\n\n    public function returnTo(string $className): self\n    {\n        $this->className = $className;\n        return $this;\n    }\n\n    public function make(string $text, array $payload = []): InlineKeyboardButton\n    {\n        // Find valid hash\n        do {\n            $hash = Str::random(32);\n            $cacheKey = 'CallbackQuery:'.$hash;\n        } while (Cache::has($cacheKey));\n\n        // Save payload\n        $payload = $payload + $this->data;\n        if (isset($this->className)) {\n            $payload['__class'] = $this->className;\n        }\n        Cache::put($cacheKey, $payload);\n\n        // Assemble button\n        return new InlineKeyboardButton([\n            'text'          => $text,\n            'callback_data' => $hash\n        ]);\n    }\n\n}\n"
  },
  {
    "path": "src/Http/Middleware/TrustTelegramNetwork.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Http\\Middleware;\n\nuse Closure;\nuse Illuminate\\Support\\Facades\\App;\nuse Symfony\\Component\\HttpFoundation\\IpUtils;\n\nclass TrustTelegramNetwork\n{\n\n    /**\n     * Trusted Telegram IP addresses\n     * @see https://core.telegram.org/bots/webhooks#the-short-version\n     * @var array\n     */\n    protected array $trustedIpNets = [\n        '149.154.160.0/20',\n        '91.108.4.0/22'\n    ];\n\n    /**\n     * Local networks for debugging\n     * @var array|string[]\n     */\n    protected array $localIpNets = [\n        '127.0.0.1/32',\n        '10.0.0.0/8',\n        '172.16.0.0/12',\n        '192.168.0.0/16'\n    ];\n\n    /**\n     * Handle an incoming request.\n     *\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @param  \\Closure  $next\n     * @return mixed\n     */\n    public function handle($request, Closure $next)\n    {\n        if (App::environment('local') && IpUtils::checkIp($request->ip(), $this->localIpNets)) {\n            return $next($request);\n        }\n\n        if (IpUtils::checkIp($request->ip(), $this->trustedIpNets)) {\n            return $next($request);\n        }\n\n        abort(403);\n    }\n}\n"
  },
  {
    "path": "src/LaravelTelegramBot.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel;\n\nuse Longman\\TelegramBot\\Entities\\ServerResponse;\nuse Longman\\TelegramBot\\Entities\\Update;\nuse Longman\\TelegramBot\\Request;\n\nclass LaravelTelegramBot\n{\n\n    protected array $callbacks = [];\n\n    public function register(callable $callback)\n    {\n        $this->callbacks[] = $callback;\n    }\n\n    public function call(Update $update): ?ServerResponse\n    {\n        foreach ($this->callbacks as $callback) {\n            $return = $callback($update);\n\n            if ($return instanceof ServerResponse) {\n                return $return;\n            } elseif ($return === true) {\n                return Request::emptyResponse();\n            }\n        }\n\n        return null;\n    }\n\n}\n"
  },
  {
    "path": "src/Telegram/Commands/CallbackqueryCommand.php",
    "content": "<?php\n\n\nnamespace PhpTelegramBot\\Laravel\\Telegram\\Commands;\n\n\nuse Illuminate\\Support\\Facades\\App;\nuse Longman\\TelegramBot\\Commands\\Command;\nuse Longman\\TelegramBot\\Commands\\SystemCommand;\nuse Longman\\TelegramBot\\Conversation;\nuse Longman\\TelegramBot\\Entities\\ServerResponse;\nuse Longman\\TelegramBot\\Request;\nuse PhpTelegramBot\\Laravel\\Facades\\Telegram;\nuse PhpTelegramBot\\Laravel\\Telegram\\Conversation\\ConversationWrapper;\nuse PhpTelegramBot\\Laravel\\Telegram\\InlineKeyboardButton\\RemembersCallbackPayload;\nuse PhpTelegramBot\\Laravel\\Telegram\\UsesEffectiveEntities;\n\nclass CallbackqueryCommand extends SystemCommand\n{\n    use RemembersCallbackPayload, UsesEffectiveEntities;\n\n    protected $name = 'callbackquery';\n    protected $description = 'Handles CallbackQueries';\n    protected $version = '1.0';\n\n    public function execute(): ServerResponse\n    {\n        $return = Telegram::call($this->getUpdate());\n        if ($return instanceof ServerResponse) {\n            return $return;\n        }\n\n        // Check if we have data for that hash in the Cache\n        if ($class = $this->payload()?->get('__class')) {\n            if (class_exists($class) && is_subclass_of($class, Command::class)) {\n                /** @var Command $command */\n                $command = new $class($this->telegram, $this->update);\n                return $command->preExecute();\n            }\n        }\n\n        // Check if conversation is active\n        $user = $this->getEffectiveUser($this->getUpdate());\n        $chat = $this->getEffectiveChat($this->getUpdate());\n\n        $conversation = new Conversation(\n            user_id: $user->getId(),\n            chat_id: $chat->getId()\n        );\n\n        if ($conversation->exists() && ($command = $conversation->getCommand())) {\n            return $this->getTelegram()->executeCommand($command);\n        }\n\n        // Check if own CallbackqueryCommand class is available\n        $class = App::getNamespace() . 'Telegram\\\\Commands\\\\CallbackqueryCommand';\n        if (class_exists($class) && is_subclass_of($class, SystemCommand::class)) {\n            /** @var SystemCommand $command */\n            $command = new $class($this->telegram, $this->update);\n            return $command->preExecute();\n        }\n\n        return Request::emptyResponse();\n    }\n}\n"
  },
  {
    "path": "src/Telegram/Commands/GenericmessageCommand.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Telegram\\Commands;\n\nuse Illuminate\\Support\\Facades\\App;\nuse Longman\\TelegramBot\\Commands\\SystemCommand;\nuse Longman\\TelegramBot\\Conversation;\nuse Longman\\TelegramBot\\Entities\\ServerResponse;\nuse Longman\\TelegramBot\\Request;\nuse PhpTelegramBot\\Laravel\\Facades\\Telegram;\nuse PhpTelegramBot\\Laravel\\Telegram\\Conversation\\ConversationWrapper;\nuse PhpTelegramBot\\Laravel\\Telegram\\UsesEffectiveEntities;\n\nclass GenericmessageCommand extends SystemCommand\n{\n    use UsesEffectiveEntities;\n\n    protected $name = 'genericmessage';\n    protected $description = 'Handles Genericmessages';\n    protected $version = '1.0';\n\n    public function execute(): ServerResponse\n    {\n        $return = Telegram::call($this->getUpdate());\n        if ($return instanceof ServerResponse) {\n            return $return;\n        }\n\n        $user = $this->getEffectiveUser($this->getUpdate());\n        $chat = $this->getEffectiveChat($this->getUpdate());\n\n        // Check Conversation\n        $conversation = new Conversation(\n            user_id: $user->getId(),\n            chat_id: $chat->getId()\n        );\n\n        if ($conversation->exists() && ($command = $conversation->getCommand())) {\n            return $this->getTelegram()->executeCommand($command);\n        }\n\n        // Check if own GenericmessageCommand class is available\n        $class = App::getNamespace() . 'Telegram\\\\Commands\\\\GenericmessageCommand';\n        if (class_exists($class) && is_subclass_of($class, SystemCommand::class)) {\n            /** @var SystemCommand $command */\n            $command = new $class($this->telegram, $this->update);\n            return $command->preExecute();\n        }\n\n        return Request::emptyResponse();\n    }\n\n}"
  },
  {
    "path": "src/Telegram/Conversation/ConversationWrapper.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Telegram\\Conversation;\n\nuse Longman\\TelegramBot\\Conversation;\nuse Longman\\TelegramBot\\Entities\\Update;\n\nclass ConversationWrapper\n{\n\n    protected Conversation $conversation;\n    protected array $temporary = [];\n\n    public function __construct(Update $update, $command = '')\n    {\n        if ($message = $update->getMessage() ?? $update->getEditedMessage()) {\n            $user = $message->getFrom();\n            $chat = $message->getChat();\n        } elseif ($callbackQuery = $update->getCallbackQuery()) {\n            $user = $callbackQuery->getFrom();\n            $chat = $callbackQuery->getMessage()?->getChat();\n        }\n\n        // TODO: Use getEffective*() Methods that should be created in \\Bot Facade\n\n        if (! isset($user) || ! isset($chat)) {\n            throw new \\InvalidArgumentException('Could not determine user or chat for ConversationWrapper');\n        }\n\n        $this->conversation = new Conversation(\n            user_id: $user->getId(),\n            chat_id: $chat->getId(),\n            command: $command\n        );\n\n        $notes = &$this->conversation->notes;\n        $notes['vars'] ??= [];\n        $notes['persist'] ??= [];\n\n        if ($this->conversation->exists()) {\n            // Remove temporary variables\n            foreach ($notes['vars'] as $key => $value) {\n                if (array_search($key, $notes['persist']) === false) {\n                    // Is temporary\n                    $this->temporary[$key] = $value;\n                    unset($notes['vars'][$key]);\n                }\n            }\n            $this->conversation->update();\n        }\n    }\n\n    public function all(): array\n    {\n        return $this->conversation->notes['vars'] + $this->temporary;\n    }\n\n    public function get(string $key, string $default = null): mixed\n    {\n        return data_get($this->conversation->notes['vars'], $key)\n            ?? data_get($this->temporary, $key, $default);\n    }\n\n    public function has(string $key): bool\n    {\n        return $this->get($key) !== null;\n    }\n\n    public function getConversation(): Conversation\n    {\n        return $this->conversation;\n    }\n\n    public function persist(array $data): self\n    {\n        $notes = &$this->conversation->notes;\n        foreach ($data as $key => $value) {\n            $notes['vars'][$key] = $value;\n            $notes['persist'][] = $key;\n        }\n        $this->conversation->update();\n\n        return $this;\n    }\n\n    public function remember(array $data = [], bool $keepPreviousData = false): self\n    {\n        $notes = &$this->conversation->notes;\n\n        if ($keepPreviousData) {\n            foreach ($this->temporary as $key => $value) {\n                $notes['vars'][$key] = $value;\n            }\n        }\n\n        foreach ($data as $key => $value) {\n            $notes['vars'][$key] = $value;\n            $index = array_search($key, $notes['persist']);\n            if ($index !== false) {\n                unset($notes['persist'][$index]);\n            }\n        }\n\n        $notes['persist'] = array_values($notes['persist']);\n        $this->conversation->update();\n        return $this;\n    }\n\n    public function exists(): bool\n    {\n        return $this->conversation->exists();\n    }\n\n    public function end(): void\n    {\n        $this->conversation->stop();\n    }\n\n    public function cancel(): void\n    {\n        $this->conversation->cancel();\n    }\n\n}\n"
  },
  {
    "path": "src/Telegram/Conversation/LeadsConversation.php",
    "content": "<?php\n\n\nnamespace PhpTelegramBot\\Laravel\\Telegram\\Conversation;\n\nuse Longman\\TelegramBot\\Entities\\Update;\n\n/**\n * Trait LeadsConversation\n * @package PhpTelegramBot\\Laravel\n * @method Update getUpdate()\n * @method string getName()\n */\ntrait LeadsConversation\n{\n\n    /**\n     * @internal\n     */\n    protected ?ConversationWrapper $conversation;\n\n    /**\n     * @param  string|null  $key\n     * @param  string|null  $default\n     * @return ?ConversationWrapper|mixed\n     */\n    protected function conversation(string $key = null, string $default = null)\n    {\n        if (! isset($this->conversation)) {\n            $this->conversation = new ConversationWrapper($this->getUpdate(), $this->getName());\n        }\n\n        if (isset($key)) {\n            return $this->conversation->get($key, $default);\n        }\n\n        return $this->conversation;\n    }\n\n}\n"
  },
  {
    "path": "src/Telegram/InlineKeyboardButton/CallbackPayload.php",
    "content": "<?php\n\n\nnamespace PhpTelegramBot\\Laravel\\Telegram\\InlineKeyboardButton;\n\n\nclass CallbackPayload\n{\n\n    public function __construct(protected array $payload)\n    {\n    }\n\n    public function all(): array\n    {\n        return $this->payload;\n    }\n\n    public function get(string $key, string $default = null): mixed\n    {\n        return data_get($this->payload, $key, $default);\n    }\n\n    public function has(string $key): bool\n    {\n        return $this->get($key) !== null;\n    }\n\n}\n"
  },
  {
    "path": "src/Telegram/InlineKeyboardButton/RemembersCallbackPayload.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Telegram\\InlineKeyboardButton;\n\n\nuse Illuminate\\Support\\Facades\\Cache;\nuse Longman\\TelegramBot\\Commands\\Command;\nuse Longman\\TelegramBot\\Entities\\Update;\n\n/**\n * Trait CallbackQueryCache\n * @package PhpTelegramBot\\Laravel\\Services\n * @method Update getUpdate()\n */\ntrait RemembersCallbackPayload\n{\n    /**\n     * @var CallbackPayload\n     * @internal\n     */\n    protected ?CallbackPayload $payload;\n\n    /**\n     * @param string|null $key\n     * @param string|null $default\n     * @return CallbackPayload|null|mixed\n     */\n    protected function payload(string $key = null, string $default = null)\n    {\n        if (! isset($this->payload)) {\n            $update = $this->getUpdate();\n            $data = $update?->getCallbackQuery()?->getData();\n\n            if ($data === null) {\n                return null;\n            }\n\n            // TODO: Move CacheKey and initialization in CallbackPayload::__construct()\n            $cacheKey = 'CallbackQuery:'.$data;\n\n            if (! Cache::has($cacheKey)) {\n                return null;\n            }\n\n            $payload = Cache::get($cacheKey);\n            $this->payload = new CallbackPayload($payload);\n        }\n\n        if (isset($key)) {\n            return $this->payload->get($key, $default);\n        }\n\n        return $this->payload;\n    }\n\n}\n"
  },
  {
    "path": "src/Telegram/UsesEffectiveEntities.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel\\Telegram;\n\nuse Longman\\TelegramBot\\Entities\\Chat;\nuse Longman\\TelegramBot\\Entities\\Message;\nuse Longman\\TelegramBot\\Entities\\Update;\nuse Longman\\TelegramBot\\Entities\\User;\n\ntrait UsesEffectiveEntities\n{\n\n    protected function getEffectiveUser(Update $update): ?User\n    {\n        $type = $update->getUpdateType();\n\n        $user = $update->$type['from']\n            ?? $update->poll_answer['user']\n            ?? null;\n\n        return $user ? new User($user) : null;\n    }\n\n    protected function getEffectiveChat(Update $update): ?Chat\n    {\n        $type = $update->getUpdateType();\n\n        $chat = $update->$type['chat']\n            ?? $update->callback_query['message']['chat']\n            ?? null;\n\n        return $chat ? new Chat($chat) : null;\n    }\n\n    protected function getEffectiveMessage(Update $update): ?Message\n    {\n        $message = $update->edited_channel_post\n            ?? $update->channel_post\n            ?? $update->callback_query['message']\n            ?? $update->edited_message\n            ?? $update->message\n            ?? null;\n\n        return $message ? new Message($message) : null;\n    }\n\n}"
  },
  {
    "path": "src/TelegramServiceProvider.php",
    "content": "<?php\n\nnamespace PhpTelegramBot\\Laravel;\n\nuse Illuminate\\Routing\\Router;\nuse Illuminate\\Support\\Facades\\File;\nuse Illuminate\\Support\\ServiceProvider;\nuse Longman\\TelegramBot\\Commands\\Command;\nuse Longman\\TelegramBot\\Request;\nuse Longman\\TelegramBot\\Telegram;\nuse Symfony\\Component\\Finder\\Finder;\nuse PhpTelegramBot\\Laravel\\Console\\Commands\\TelegramCloseCommand;\nuse PhpTelegramBot\\Laravel\\Console\\Commands\\TelegramDeleteWebhookCommand;\nuse PhpTelegramBot\\Laravel\\Console\\Commands\\TelegramFetchCommand;\nuse PhpTelegramBot\\Laravel\\Console\\Commands\\TelegramLogoutCommand;\nuse PhpTelegramBot\\Laravel\\Console\\Commands\\TelegramPublishCommand;\nuse PhpTelegramBot\\Laravel\\Console\\Commands\\TelegramSetWebhookCommand;\nuse PhpTelegramBot\\Laravel\\Console\\Commands\\MakeTelegramCommand;\nuse PhpTelegramBot\\Laravel\\Factories\\CallbackButton;\nuse PhpTelegramBot\\Laravel\\Http\\Middleware\\TrustTelegramNetwork;\nuse PhpTelegramBot\\Laravel\\Telegram\\Commands\\CallbackqueryCommand;\nuse PhpTelegramBot\\Laravel\\Telegram\\Commands\\GenericmessageCommand;\n\nclass TelegramServiceProvider extends ServiceProvider\n{\n    /**\n     * Perform post-registration booting of services.\n     *\n     * @return void\n     */\n    public function boot(): void\n    {\n        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');\n\n        if (file_exists(base_path('routes/telegram.php'))) {\n            $this->loadRoutesFrom(base_path('routes/telegram.php'));\n        } else {\n            $this->loadRoutesFrom(__DIR__ . '/../routes/telegram.php');\n        }\n\n        $router = $this->app->make(Router::class);\n        $router->aliasMiddleware('telegram.network', TrustTelegramNetwork::class);\n\n        // Publishing is only necessary when using the CLI.\n        if ($this->app->runningInConsole()) {\n            $this->bootForConsole();\n        }\n    }\n\n    /**\n     * Register any package services.\n     *\n     * @return void\n     */\n    public function register(): void\n    {\n        $this->mergeConfigFrom(__DIR__ . '/../config/telegram.php', 'telegram');\n\n        $this->configureTelegramBot();\n    }\n\n    protected function configureTelegramBot()\n    {\n        $token = config('telegram.bot.api_token');\n\n        if (! $token) {\n            return;\n        }\n\n        $username = config('telegram.bot.username');\n\n        $apiUrl = config('telegram.bot.api_url', '');\n        if (! empty($apiUrl)) {\n            Request::setCustomBotApiUri($apiUrl);\n        }\n\n        $bot = new Telegram($token, $username);\n\n        // Commands Discovery\n        $this->discoverTelegramCommands($bot);\n        $bot->addCommandClass(CallbackqueryCommand::class);\n        $bot->addCommandClass(GenericmessageCommand::class);\n\n        // Set MySQL Connection\n        $connection = app('db')->connection('mysql');\n        $bot->enableExternalMySql($connection->getPdo(), 'bot_');\n\n        // Register admins\n        $this->registerTelegramAdmins($bot);\n\n        $this->app->instance(Telegram::class, $bot);\n    }\n\n    /**\n     * Console-specific booting.\n     *\n     * @return void\n     */\n    protected function bootForConsole(): void\n    {\n        // Publishing the configuration file.\n        $this->publishes([\n            __DIR__ . '/../config/telegram.php' => config_path('telegram.php'),\n        ], 'telegram-config');\n\n        $this->publishes([\n            __DIR__ . '/../routes/telegram.php' => base_path('routes/telegram.php')\n        ], 'telegram-routes');\n\n        // Registering package commands.\n        $this->commands([\n            MakeTelegramCommand::class,\n            TelegramCloseCommand::class,\n            TelegramDeleteWebhookCommand::class,\n            TelegramFetchCommand::class,\n            TelegramLogoutCommand::class,\n            TelegramPublishCommand::class,\n            TelegramSetWebhookCommand::class,\n        ]);\n    }\n\n    /**\n     * @param  Telegram  $bot\n     * @throws \\ReflectionException\n     */\n    protected function discoverTelegramCommands(Telegram $bot): void\n    {\n        $namespace = $this->app->getNamespace();\n        $commandsPath = app_path('Telegram/Commands');\n        File::ensureDirectoryExists($commandsPath);\n\n        foreach ((new Finder)->in($commandsPath)->files() as $command) {\n            $command = $namespace . str_replace(\n                    ['/', '.php'],\n                    ['\\\\', ''],\n                    \\Str::after($command->getRealPath(), realpath(app_path()) . DIRECTORY_SEPARATOR)\n                );\n\n            if (is_subclass_of($command, Command::class) &&\n                ! (new \\ReflectionClass($command))->isAbstract()) {\n                $bot->addCommandClass($command);\n            }\n        }\n    }\n\n    /**\n     * @param  Telegram  $bot\n     */\n    protected function registerTelegramAdmins(Telegram $bot): void\n    {\n        $admins = config('telegram.admins', '');\n        if (! empty($admins)) {\n            $admins = explode(',', $admins);\n            $bot->enableAdmins($admins);\n        }\n    }\n}\n"
  }
]