├── .gitignore ├── controllers ├── chats │ ├── index.htm │ ├── _list_toolbar.htm │ ├── config_list.yaml │ ├── _control.htm │ └── _send_modal.htm ├── users │ ├── index.htm │ ├── _list_toolbar.htm │ └── config_list.yaml ├── messages │ ├── index.htm │ ├── _list_toolbar.htm │ └── config_list.yaml ├── Users.php ├── Messages.php └── Chats.php ├── plot ├── config-snippets1.png ├── grid.cfg ├── xyborder.cfg ├── mathematics.cfg ├── dark2.pal └── config-snippets1.gnu ├── .editorconfig ├── classes ├── widgetdesigntimeprovider │ └── partials │ │ └── _control-telechat.htm ├── WidgetDesignTimeProvider.php ├── RegisterWidgets.php └── TelegramApi.php ├── formwidgets ├── checkwebhook │ └── partials │ │ ├── _body.htm │ │ └── _wnd.htm ├── telegramchat │ └── partials │ │ └── _body.htm ├── CheckWebhook.php └── TelegramChat.php ├── commands ├── UserCommand.php ├── AdminCommand.php ├── SystemCommands │ ├── LeftchatmemberCommand.php │ ├── NewchatphotoCommand.php │ ├── NewchattitleCommand.php │ ├── DeletechatphotoCommand.php │ ├── MigratetochatidCommand.php │ ├── GroupchatcreatedCommand.php │ ├── MigratefromchatidCommand.php │ ├── ChannelchatcreatedCommand.php │ ├── SupergroupchatcreatedCommand.php │ ├── EditedmessageCommand.php │ ├── ChoseninlineresultCommand.php │ ├── StartCommand.php │ ├── NewchatmemberCommand.php │ ├── CallbackqueryCommand.php │ ├── GenericCommand.php │ ├── GenericmessageCommand.php │ └── InlinequeryCommand.php ├── SystemCommand.php └── UserCommands │ └── HelpCommand.php ├── models ├── message │ └── columns.yaml ├── user │ └── columns.yaml ├── chat │ └── columns.yaml ├── User.php ├── Message.php ├── Chat.php ├── telegraminfosettings │ └── fields.yaml └── TelegramInfoSettings.php ├── composer.json ├── updates ├── version.yaml ├── builder_table_create_theone74_telegram_botan_shortener.php ├── builder_table_create_theone74_telegram_user.php ├── builder_table_create_theone74_telegram_chat.php ├── builder_table_create_theone74_telegram_inline_query.php ├── builder_table_create_theone74_telegram_user_chat.php ├── builder_table_create_theone74_telegram_callback_query.php ├── builder_table_create_theone74_telegram_chosen_inline_result.php ├── fix_callback_query.php ├── builder_table_create_theone74_telegram_conversation.php ├── builder_table_create_theone74_telegram_edited_message.php ├── builder_table_create_theone74_telegram_telegram_update.php └── builder_table_create_theone74_telegram_message.php ├── LICENSE ├── routes.php ├── README.md ├── Plugin.php ├── plugin.yaml └── lang ├── en └── lang.php └── ru └── lang.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | vendor 3 | composer.lock 4 | -------------------------------------------------------------------------------- /controllers/chats/index.htm: -------------------------------------------------------------------------------- 1 | listRender() ?> 2 | -------------------------------------------------------------------------------- /controllers/users/index.htm: -------------------------------------------------------------------------------- 1 | listRender() ?> 2 | -------------------------------------------------------------------------------- /controllers/messages/index.htm: -------------------------------------------------------------------------------- 1 | listRender() ?> 2 | -------------------------------------------------------------------------------- /controllers/chats/_list_toolbar.htm: -------------------------------------------------------------------------------- 1 |
2 |
3 | -------------------------------------------------------------------------------- /controllers/users/_list_toolbar.htm: -------------------------------------------------------------------------------- 1 |
2 |
3 | -------------------------------------------------------------------------------- /controllers/messages/_list_toolbar.htm: -------------------------------------------------------------------------------- 1 |
2 |
3 | -------------------------------------------------------------------------------- /plot/config-snippets1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/theone74/oc-telegram-plugin/HEAD/plot/config-snippets1.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style=tab 5 | indent_size=4 6 | 7 | [*.yaml] 8 | indent_style=space 9 | indent_size=4 -------------------------------------------------------------------------------- /plot/grid.cfg: -------------------------------------------------------------------------------- 1 | # Add light grid to plot 2 | # 3 | # AUTHOR: Hagen Wierstorf 4 | set style line 102 lc rgb '#d6d7d9' lt 1 lw 1 5 | set grid back ls 102 6 | -------------------------------------------------------------------------------- /classes/widgetdesigntimeprovider/partials/_control-telechat.htm: -------------------------------------------------------------------------------- 1 |
2 | Telegram Chat 3 |
-------------------------------------------------------------------------------- /plot/xyborder.cfg: -------------------------------------------------------------------------------- 1 | # xy-border for next graph 2 | # 3 | # AUTHOR: Hagen Wierstorf 4 | set style line 101 lc rgb '#808080' lt 1 lw 1 5 | set border 3 front ls 101 6 | set tics nomirror out scale 0.75 7 | set format '%g' 8 | -------------------------------------------------------------------------------- /formwidgets/checkwebhook/partials/_body.htm: -------------------------------------------------------------------------------- 1 |
2 | 9 |
-------------------------------------------------------------------------------- /controllers/chats/config_list.yaml: -------------------------------------------------------------------------------- 1 | list: $/theone74/telegram/models/chat/columns.yaml 2 | modelClass: TheOne74\Telegram\Models\Chat 3 | title: Chats 4 | noRecordsMessage: 'backend::lang.list.no_records' 5 | showSetup: true 6 | showCheckboxes: true 7 | recordsPerPage: 15 8 | toolbar: 9 | buttons: list_toolbar 10 | search: 11 | prompt: 'backend::lang.list.search_prompt' 12 | -------------------------------------------------------------------------------- /controllers/users/config_list.yaml: -------------------------------------------------------------------------------- 1 | title: Users 2 | modelClass: TheOne74\Telegram\Models\User 3 | list: $/theone74/telegram/models/user/columns.yaml 4 | noRecordsMessage: 'backend::lang.list.no_records' 5 | showSetup: true 6 | showCheckboxes: true 7 | showSorting: 1 8 | recordsPerPage: 15 9 | toolbar: 10 | buttons: list_toolbar 11 | search: 12 | prompt: 'backend::lang.list.search_prompt' 13 | -------------------------------------------------------------------------------- /controllers/messages/config_list.yaml: -------------------------------------------------------------------------------- 1 | title: Messages 2 | modelClass: TheOne74\Telegram\Models\Message 3 | list: $/theone74/telegram/models/message/columns.yaml 4 | noRecordsMessage: 'backend::lang.list.no_records' 5 | showSetup: true 6 | showCheckboxes: true 7 | showSorting: 1 8 | recordsPerPage: 15 9 | toolbar: 10 | buttons: list_toolbar 11 | search: 12 | prompt: 'backend::lang.list.search_prompt' 13 | -------------------------------------------------------------------------------- /controllers/chats/_control.htm: -------------------------------------------------------------------------------- 1 | user->hasAccess('theone74.telegram.send')): ?> 2 | 9 | 10 | -------------------------------------------------------------------------------- /commands/UserCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\Command; 12 | 13 | /** 14 | * Abstract User Command Class 15 | */ 16 | abstract class UserCommand extends Command 17 | { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /commands/AdminCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\Command; 12 | 13 | /** 14 | * Abstract Admin Command Class 15 | */ 16 | abstract class AdminCommand extends Command 17 | { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /plot/mathematics.cfg: -------------------------------------------------------------------------------- 1 | # definition of mathematical helper functions 2 | # 3 | # AUTHOR: Hagen Wierstorf 4 | 5 | # degree to radian conversion 6 | rad(phi) = phi/180.0*pi 7 | 8 | # radian to degree conversion 9 | deg(phi) = phi/pi*180.0 10 | 11 | # Bessel functions (after Bronstein 2001, eq. 9.54a) 12 | # besj0(x) and besj1(x) are build-in functions 13 | besj2(x) = 2*1/x * besj1(x) - besj0(x) 14 | besj3(x) = 2*2/x * besj2(x) - besj1(x) 15 | besj4(x) = 2*3/x * besj3(x) - besj2(x) 16 | besj5(x) = 2*4/x * besj4(x) - besj3(x) 17 | besj6(x) = 2*5/x * besj5(x) - besj4(x) 18 | -------------------------------------------------------------------------------- /controllers/Users.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Backend\Classes\Controller; 12 | use BackendMenu; 13 | 14 | class Users extends Controller 15 | { 16 | public $implement = ['Backend\Behaviors\ListController']; 17 | public $requiredPermissions = ['theone74.telegram.show.users']; 18 | 19 | public $listConfig = 'config_list.yaml'; 20 | 21 | public function __construct() 22 | { 23 | parent::__construct(); 24 | BackendMenu::setContext('TheOne74.Telegram', 'main-menu-item', 'side-menu-item'); 25 | } 26 | } -------------------------------------------------------------------------------- /controllers/Messages.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Backend\Classes\Controller; 12 | use BackendMenu; 13 | 14 | class Messages extends Controller 15 | { 16 | public $implement = ['Backend\Behaviors\ListController']; 17 | public $requiredPermissions = ['theone74.telegram.show.messages']; 18 | 19 | public $listConfig = 'config_list.yaml'; 20 | 21 | public function __construct() 22 | { 23 | parent::__construct(); 24 | BackendMenu::setContext('TheOne74.Telegram', 'main-menu-item', 'side-menu-item2'); 25 | } 26 | } -------------------------------------------------------------------------------- /models/message/columns.yaml: -------------------------------------------------------------------------------- 1 | columns: 2 | id: 3 | label: 'theone74.telegram::lang.lists.id' 4 | type: number 5 | searchable: true 6 | sortable: true 7 | username: 8 | label: 'theone74.telegram::lang.lists.username' 9 | type: text 10 | searchable: false 11 | sortable: false 12 | relation: user 13 | valueFrom: username_str 14 | chat: 15 | label: 'theone74.telegram::lang.lists.chat' 16 | type: text 17 | relation: chat 18 | sortable: false 19 | searchable: false 20 | valueFrom: listTitle 21 | text: 22 | label: 'theone74.telegram::lang.lists.text' 23 | type: text 24 | searchable: true 25 | date: 26 | label: 'theone74.telegram::lang.lists.date' 27 | type: number 28 | sortable: true 29 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "theone74/telegram", 3 | "description": "Telegram bot api implementation", 4 | "repositories": [ 5 | { 6 | "type":"package", 7 | "package": { 8 | "name": "longman/php-telegram-bot", 9 | "version":"0.35", 10 | "source": { 11 | "url": "https://github.com/theone74/php-telegram-bot.git", 12 | "type": "git", 13 | "reference":"master" 14 | } 15 | } 16 | } 17 | ], 18 | "require": { 19 | "longman/php-telegram-bot": "*", 20 | "monolog/monolog": "^1.19", 21 | "guzzlehttp/guzzle": "~6.0" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "Longman\\TelegramBot\\": "vendor/longman/php-telegram-bot/src/" 26 | } 27 | }, 28 | "authors": [ 29 | { 30 | "name": "Anton Romanov", 31 | "email": "iam@theone74.ru" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /updates/version.yaml: -------------------------------------------------------------------------------- 1 | 1.0.1: 2 | - Initialize plugin. 3 | - builder_table_create_theone74_telegram_user.php 4 | - builder_table_create_theone74_telegram_chat.php 5 | - builder_table_create_theone74_telegram_user_chat.php 6 | - builder_table_create_theone74_telegram_inline_query.php 7 | - builder_table_create_theone74_telegram_chosen_inline_result.php 8 | - builder_table_create_theone74_telegram_callback_query.php 9 | - builder_table_create_theone74_telegram_message.php 10 | - builder_table_create_theone74_telegram_edited_message.php 11 | - builder_table_create_theone74_telegram_telegram_update.php 12 | - builder_table_create_theone74_telegram_conversation.php 13 | - builder_table_create_theone74_telegram_botan_shortener.php 14 | 1.0.2: 15 | - Fix error message in settings 16 | 1.0.3: 17 | - Check webhook button 18 | 1.0.4: 19 | - Add some columns 20 | - fix_callback_query.php -------------------------------------------------------------------------------- /classes/WidgetDesignTimeProvider.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use RainLab\Builder\Widgets\DefaultControlDesignTimeProvider; 12 | 13 | class WidgetDesignTimeProvider extends DefaultControlDesignTimeProvider { 14 | 15 | public function renderControlBody($type, $properties, $formBuilder) 16 | { 17 | if ($type == 'telechat') { 18 | return $this->makePartial('control-telechat', [ 19 | 'properties'=>$properties, 20 | 'formBuilder' => $formBuilder 21 | ]); 22 | } 23 | 24 | parent::renderControlBody($type, $properties, $formBuilder); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /models/user/columns.yaml: -------------------------------------------------------------------------------- 1 | columns: 2 | id: 3 | label: 'theone74.telegram::lang.lists.id' 4 | type: number 5 | searchable: true 6 | sortable: true 7 | name: 8 | label: 'theone74.telegram::lang.lists.name' 9 | type: text 10 | searchable: true 11 | sortable: true 12 | select: 'concat(IFNULL(first_name, ''''), '' '', IFNULL(last_name,''''))' 13 | username: 14 | label: 'theone74.telegram::lang.lists.username' 15 | type: text 16 | searchable: false 17 | sortable: false 18 | created_at: 19 | label: 'theone74.telegram::lang.lists.created_at' 20 | type: datetime 21 | searchable: false 22 | sortable: true 23 | upated_at: 24 | label: 'theone74.telegram::lang.lists.upated_at' 25 | type: datetime 26 | searchable: false 27 | sortable: true 28 | invisible: true 29 | -------------------------------------------------------------------------------- /plot/dark2.pal: -------------------------------------------------------------------------------- 1 | # line styles for ColorBrewer Dark2 2 | # for use with qualitative/categorical data 3 | # provides 8 dark colors based on Set2 4 | # compatible with gnuplot >=4.2 5 | # author: Anna Schneider 6 | 7 | # line styles 8 | set style line 1 lt 1 lc rgb '#1B9E77' # dark teal 9 | set style line 2 lt 1 lc rgb '#D95F02' # dark orange 10 | set style line 3 lt 1 lc rgb '#7570B3' # dark lilac 11 | set style line 4 lt 1 lc rgb '#E7298A' # dark magenta 12 | set style line 5 lt 1 lc rgb '#66A61E' # dark lime green 13 | set style line 6 lt 1 lc rgb '#E6AB02' # dark banana 14 | set style line 7 lt 1 lc rgb '#A6761D' # dark tan 15 | set style line 8 lt 1 lc rgb '#666666' # dark gray 16 | 17 | # palette 18 | set palette maxcolors 8 19 | set palette defined ( 0 '#1B9E77',\ 20 | 1 '#D95F02',\ 21 | 2 '#7570B3',\ 22 | 3 '#E7298A',\ 23 | 4 '#66A61E',\ 24 | 5 '#E6AB02',\ 25 | 6 '#A6761D',\ 26 | 7 '#666666' ) 27 | -------------------------------------------------------------------------------- /commands/SystemCommands/LeftchatmemberCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Left chat member command 15 | */ 16 | class LeftchatmemberCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Leftchatmember'; 22 | protected $description = 'Left Chat Member'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$member = $message->getLeftChatMember(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/NewchatphotoCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * New chat photo command 15 | */ 16 | class NewchatphotoCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Newchatphoto'; 22 | protected $description = 'New chat Photo'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$new_chat_photo = $message->getNewChatPhoto(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/NewchattitleCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * New chat title command 15 | */ 16 | class NewchattitleCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Newchattitle'; 22 | protected $description = 'New chat Title'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$new_chat_title = $message->getNewChatTitle(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/DeletechatphotoCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Delete chat photo command 15 | */ 16 | class DeletechatphotoCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Deletechatphoto'; 22 | protected $description = 'Delete chat photo'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$delete_chat_photo = $message->getDeleteChatPhoto(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/MigratetochatidCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Migrate to chat id command 15 | */ 16 | class MigratetochatidCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Migratetochatid'; 22 | protected $description = 'Migrate to chat id'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$migrate_to_chat_id = $message->getMigrateToChatId(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/GroupchatcreatedCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Group chat created command 15 | */ 16 | class GroupchatcreatedCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Groupchatcreated'; 22 | protected $description = 'Group chat created'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$group_chat_created = $message->getGroupChatCreated(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/MigratefromchatidCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Migrate from chat id command 15 | */ 16 | class MigratefromchatidCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Migratefromchatid'; 22 | protected $description = 'Migrate from chat id'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$migrate_from_chat_id = $message->getMigrateFromChatId(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\Command; 12 | use Longman\TelegramBot\Request; 13 | 14 | /** 15 | * Abstract System Command Class 16 | */ 17 | abstract class SystemCommand extends Command 18 | { 19 | /** 20 | * A system command just executes 21 | * 22 | * Although system commands should just work and return a successful ServerResponse, 23 | * each system command can override this method to add custom functionality. 24 | * 25 | * @return Entities\ServerResponse 26 | */ 27 | public function execute() 28 | { 29 | //System command, return empty ServerResponse 30 | return Request::emptyResponse(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /commands/SystemCommands/ChannelchatcreatedCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Channel chat created command 15 | */ 16 | class ChannelchatcreatedCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Channelchatcreated'; 22 | protected $description = 'Channel chat created'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$channel_chat_created = $message->getChannelChatCreated(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/SupergroupchatcreatedCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Super group chat created command 15 | */ 16 | class SupergroupchatcreatedCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'Supergroupchatcreated'; 22 | protected $description = 'Super group chat created'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //$message = $this->getMessage(); 32 | //$supergroup_chat_created = $message->getSuperGroupChatCreated(); 33 | }*/ 34 | } 35 | -------------------------------------------------------------------------------- /commands/SystemCommands/EditedmessageCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | use Longman\TelegramBot\Request; 13 | 14 | /** 15 | * Edited message command 16 | */ 17 | class EditedmessageCommand extends SystemCommand 18 | { 19 | /**#@+ 20 | * {@inheritdoc} 21 | */ 22 | protected $name = 'editedmessage'; 23 | protected $description = 'User edited message'; 24 | protected $version = '1.0.0'; 25 | /**#@-*/ 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function execute() 31 | { 32 | $update = $this->getUpdate(); 33 | $edited_message = $update->getEditedMessage(); 34 | trace_log($edited_message); 35 | return Request::emptyResponse(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /commands/SystemCommands/ChoseninlineresultCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | 13 | /** 14 | * Chosen inline result command 15 | */ 16 | class ChoseninlineresultCommand extends SystemCommand 17 | { 18 | /**#@+ 19 | * {@inheritdoc} 20 | */ 21 | protected $name = 'choseninlineresult'; 22 | protected $description = 'Chosen result query'; 23 | protected $version = '1.0.1'; 24 | /**#@-*/ 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | /*public function execute() 30 | { 31 | //Information about chosen result is returned 32 | //$update = $this->getUpdate(); 33 | //$inline_query = $update->getChosenInlineResult(); 34 | //$query = $inline_query->getQuery(); 35 | }*/ 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Anton Romanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /routes.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use TheOne74\Telegram\Classes\TelegramApi; 12 | use \Longman\TelegramBot\Request; 13 | use \Longman\TelegramBot\Exception\TelegramException; 14 | use \TheOne74\Telegram\Models\TelegramInfoSettings; 15 | 16 | 17 | Route::post('/telehook/{token}', array(function($token){ 18 | 19 | if (TelegramInfoSettings::instance()->get('token') != $token) { 20 | \Log::error('Undefined token '.$token); 21 | App::abort(403, 'Unauthorized action.'); 22 | return; 23 | } 24 | 25 | try { 26 | Event::fire('telegram.init', []); 27 | 28 | // Create Telegram API object 29 | $telegram = TelegramApi::instance(); 30 | 31 | Event::fire('telegram.beforeReceive', []); 32 | 33 | // Handle telegram webhook request 34 | $telegram->handle(); 35 | 36 | Event::fire('telegram.afterReceive', []); 37 | 38 | } catch (TelegramException $e) { 39 | \Log::error($e); 40 | } 41 | })); 42 | -------------------------------------------------------------------------------- /formwidgets/telegramchat/partials/_body.htm: -------------------------------------------------------------------------------- 1 | options(); 3 | ?> 4 | 5 | previewMode): ?> 6 |
value])) ? e(trans($fieldOptions[$field->value])) : '' ?>
7 | 8 | 28 | 29 | -------------------------------------------------------------------------------- /commands/SystemCommands/StartCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | use Longman\TelegramBot\Request; 13 | 14 | /** 15 | * Start command 16 | */ 17 | class StartCommand extends SystemCommand 18 | { 19 | /**#@+ 20 | * {@inheritdoc} 21 | */ 22 | protected $name = 'start'; 23 | protected $description = 'Start command'; 24 | protected $usage = '/start'; 25 | protected $version = '1.0.1'; 26 | /**#@-*/ 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function execute() 32 | { 33 | $message = $this->getMessage(); 34 | 35 | $chat_id = $message->getChat()->getId(); 36 | $text = 'Hi there!!!' . "\n" . 'Type /help to see all commands!'; 37 | 38 | $data = [ 39 | 'chat_id' => $chat_id, 40 | 'text' => $text, 41 | ]; 42 | 43 | return Request::sendMessage($data); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /models/chat/columns.yaml: -------------------------------------------------------------------------------- 1 | columns: 2 | id: 3 | label: 'theone74.telegram::lang.lists.id' 4 | type: number 5 | searchable: true 6 | sortable: true 7 | type: 8 | label: 'theone74.telegram::lang.lists.type' 9 | type: text 10 | searchable: true 11 | sortable: true 12 | title: 13 | label: 'theone74.telegram::lang.lists.title' 14 | type: text 15 | searchable: true 16 | sortable: true 17 | username_str: 18 | label: 'theone74.telegram::lang.lists.username' 19 | type: text 20 | relation: user 21 | valueFrom: username_str 22 | searchable: false 23 | sortable: false 24 | created_at: 25 | label: 'theone74.telegram::lang.lists.created_at' 26 | type: datetime 27 | searchable: false 28 | sortable: true 29 | upated_at: 30 | label: 'theone74.telegram::lang.lists.upated_at' 31 | type: datetime 32 | searchable: false 33 | sortable: true 34 | invisible: true 35 | control: 36 | label: 'theone74.telegram::lang.lists.control' 37 | type: partial 38 | cssClass: 'column-button nolink' 39 | sortable: false 40 | searchable: false 41 | -------------------------------------------------------------------------------- /models/User.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Model; 12 | 13 | /** 14 | * User Model 15 | */ 16 | class User extends Model 17 | { 18 | use \October\Rain\Database\Traits\Validation; 19 | 20 | /* 21 | * Validation 22 | */ 23 | public $rules = [ 24 | ]; 25 | 26 | /* 27 | * Disable timestamps by default. 28 | * Remove this line if timestamps are defined in the database table. 29 | */ 30 | public $timestamps = false; 31 | 32 | /** 33 | * @var string The database table used by the model. 34 | */ 35 | public $table = 'theone74_telegram_user'; 36 | 37 | function getUsernameStrAttribute() { 38 | $name = $this->id; 39 | if (($this->username)) { 40 | $name = $this->username; 41 | } 42 | else { 43 | if (($this->first_name)) { 44 | $name = $this->first_name; 45 | } 46 | if (($this->last_name)) { 47 | $name .= (isset($this->first_name) ? ' ' : '') . $this->last_name; 48 | } 49 | } 50 | return $name; 51 | } 52 | } -------------------------------------------------------------------------------- /models/Message.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Model; 12 | 13 | /** 14 | * Message Model 15 | */ 16 | class Message extends Model 17 | { 18 | use \October\Rain\Database\Traits\Validation; 19 | 20 | /* 21 | * Validation 22 | */ 23 | public $rules = [ 24 | ]; 25 | 26 | /* 27 | * Disable timestamps by default. 28 | * Remove this line if timestamps are defined in the database table. 29 | */ 30 | public $timestamps = false; 31 | 32 | /** 33 | * @var string The database table used by the model. 34 | */ 35 | public $table = 'theone74_telegram_message'; 36 | 37 | public $belongsTo = [ 38 | 'user' => [ 39 | 'TheOne74\Telegram\Models\User', 40 | // 'key' => 'my_user_id', 41 | // 'otherKey' => 'my_role_id' 42 | ], 43 | 'chat' => [ 44 | 'TheOne74\Telegram\Models\Chat', 45 | // 'key' => 'my_user_id', 46 | // 'otherKey' => 'my_role_id' 47 | ] 48 | ]; 49 | } -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_botan_shortener.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramBotanShortener extends Migration 15 | { 16 | public function down() 17 | { 18 | Schema::drop('theone74_telegram_botan_shortener'); 19 | } 20 | 21 | public function up() 22 | { 23 | Schema::create('theone74_telegram_botan_shortener', function($table) 24 | { 25 | $table->engine = 'InnoDB'; 26 | $table->bigIncrements('id')->unsigned(); 27 | $table->bigInteger('user_id')->nullable()->default(null); 28 | $table->text('url')->default(''); 29 | $table->string('short_url', 255)->default(''); 30 | $table->timestamp('created_at')->nullable()->default(null); 31 | 32 | $table->foreign('user_id') 33 | ->references('id') 34 | ->on('theone74_telegram_user'); 35 | }); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_user.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramUser extends Migration 15 | { 16 | public function up() 17 | { 18 | Schema::create('theone74_telegram_user', function($table) 19 | { 20 | $table->engine = 'InnoDB'; 21 | $table->bigInteger('id'); 22 | $table->string('first_name', 255)->default(''); 23 | $table->string('last_name', 255)->nullable()->default(null); 24 | $table->string('username', 255)->nullable()->default(null); 25 | $table->timestamp('created_at')->nullable()->default(null); 26 | $table->timestamp('updated_at')->nullable()->default(null); 27 | 28 | $table->primary('id'); 29 | $table->index(['username'], 'username'); 30 | }); 31 | } 32 | 33 | public function down() 34 | { 35 | Schema::drop('theone74_telegram_user'); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_chat.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramChat extends Migration 15 | { 16 | public function up() 17 | { 18 | Schema::create('theone74_telegram_chat', function($table) 19 | { 20 | $table->engine = 'InnoDB'; 21 | $table->bigInteger('id'); 22 | $table->enum('type', ['private', 'group', 'supergroup', 'channel']); 23 | $table->string('title', 255)->nullable()->default(''); 24 | $table->timestamp('created_at')->nullable()->default(null); 25 | $table->timestamp('updated_at')->nullable()->default(null); 26 | $table->string('old_id', 255)->nullable()->default(null); 27 | 28 | $table->primary('id'); 29 | $table->index(['old_id'], 'old_id'); 30 | }); 31 | } 32 | 33 | public function down() 34 | { 35 | Schema::drop('theone74_telegram_chat'); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /formwidgets/CheckWebhook.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Backend\Classes\FormWidgetBase; 12 | use \Longman\TelegramBot\Request; 13 | use \TheOne74\Telegram\Classes\TelegramApi; 14 | 15 | /** 16 | * Backend form widget for check webhook 17 | */ 18 | class CheckWebhook extends FormWidgetBase 19 | { 20 | protected $defaultAlias = 'checkwebhook'; 21 | 22 | public function widgetDetails() 23 | { 24 | return [ 25 | 'name' => 'Telegram check webhook button', 26 | 'description' => 'Renders field with check webhook button.' 27 | ]; 28 | } 29 | 30 | public function init() 31 | { 32 | parent::init(); 33 | } 34 | 35 | public function render() { 36 | $this->vars['field'] = $this->formField; 37 | return $this->makePartial('body', ['field' => $this->vars['field']]); 38 | } 39 | 40 | public function onCheckWebhook() { 41 | TelegramApi::instance(); 42 | $r = Request::getWebhookInfo(); 43 | return $this->makePartial('wnd', ['req' => $r]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /commands/SystemCommands/NewchatmemberCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | use Longman\TelegramBot\Request; 13 | 14 | /** 15 | * New chat member command 16 | */ 17 | class NewchatmemberCommand extends SystemCommand 18 | { 19 | /**#@+ 20 | * {@inheritdoc} 21 | */ 22 | protected $name = 'Newchatmember'; 23 | protected $description = 'New Chat Member'; 24 | protected $version = '1.0.1'; 25 | /**#@-*/ 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function execute() 31 | { 32 | $message = $this->getMessage(); 33 | 34 | $chat_id = $message->getChat()->getId(); 35 | $member = $message->getNewChatMember(); 36 | 37 | if ($message->botAddedInChat()) { 38 | $text = 'Hi there!'; 39 | } else { 40 | $text = 'Hi ' . $member->tryMention() . '!'; 41 | } 42 | 43 | $data = [ 44 | 'chat_id' => $chat_id, 45 | 'text' => $text, 46 | ]; 47 | 48 | return Request::sendMessage($data); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_inline_query.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramInlineQuery extends Migration 15 | { 16 | public function up() 17 | { 18 | Schema::create('theone74_telegram_inline_query', function($table) 19 | { 20 | $table->engine = 'InnoDB'; 21 | $table->bigIncrements('id'); 22 | $table->bigInteger('user_id')->nullable(); 23 | $table->string('location', 255)->nullable()->default(null); 24 | $table->text('query')->default(''); 25 | $table->string('offset', 255)->nullable()->default(null); 26 | $table->timestamp('created_at')->nullable()->default(null); 27 | 28 | $table->index(['user_id'], 'user_id'); 29 | 30 | $table->foreign('user_id') 31 | ->references('id') 32 | ->on('theone74_telegram_user'); 33 | }); 34 | } 35 | 36 | public function down() 37 | { 38 | Schema::drop('theone74_telegram_inline_query'); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_user_chat.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramUserChat extends Migration 15 | { 16 | public function up() 17 | { 18 | Schema::create('theone74_telegram_user_chat', function($table) 19 | { 20 | $table->engine = 'InnoDB'; 21 | $table->bigInteger('user_id'); 22 | $table->bigInteger('chat_id'); 23 | 24 | $table->primary(['user_id', 'chat_id']); 25 | 26 | $table->foreign('user_id') 27 | ->references('id') 28 | ->on('theone74_telegram_user') 29 | ->onDelete('cascade') 30 | ->onUpdate('cascade'); 31 | 32 | $table->foreign('chat_id') 33 | ->references('id') 34 | ->on('theone74_telegram_chat') 35 | ->onDelete('cascade') 36 | ->onUpdate('cascade'); 37 | }); 38 | } 39 | 40 | public function down() 41 | { 42 | Schema::drop('theone74_telegram_user_chat'); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_callback_query.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramCallbackQuery extends Migration 15 | { 16 | 17 | public function down() 18 | { 19 | Schema::drop('theone74_telegram_callback_query'); 20 | } 21 | 22 | public function up() 23 | { 24 | Schema::create('theone74_telegram_callback_query', function($table) 25 | { 26 | $table->engine = 'InnoDB'; 27 | $table->bigIncrements('id')->unsigned(); 28 | $table->bigInteger('user_id')->nullable(); 29 | $table->text('message')->nullable()->default(null); 30 | $table->string('inline_message_id', 255)->nullable()->default(null); 31 | $table->string('data', 255)->default(''); 32 | $table->timestamp('created_at')->nullable()->default(null); 33 | 34 | $table->index(['user_id'], 'user_id'); 35 | 36 | $table->foreign('user_id') 37 | ->references('id') 38 | ->on('theone74_telegram_user'); 39 | }); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /models/Chat.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Model; 12 | 13 | /** 14 | * Chat Model 15 | */ 16 | class Chat extends Model 17 | { 18 | use \October\Rain\Database\Traits\Validation; 19 | 20 | /* 21 | * Validation 22 | */ 23 | public $rules = [ 24 | ]; 25 | 26 | /* 27 | * Disable timestamps by default. 28 | * Remove this line if timestamps are defined in the database table. 29 | */ 30 | public $timestamps = false; 31 | 32 | /** 33 | * @var string The database table used by the model. 34 | */ 35 | public $table = 'theone74_telegram_chat'; 36 | 37 | public $belongsToMany = [ 38 | 'user' => [ 39 | 'TheOne74\Telegram\Models\User', 40 | 'table' => 'theone74_telegram_user_chat', 41 | ] 42 | ]; 43 | 44 | function getListTitleAttribute() { 45 | 46 | switch ($this->type) { 47 | case 'private': 48 | return sprintf('"%s" private chat', $this->user[0]->username_str); 49 | break; 50 | case 'group': 51 | return sprintf('"%s" group chat', $this->title); 52 | break; 53 | } 54 | 55 | return ''; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /commands/SystemCommands/CallbackqueryCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | 12 | use Longman\TelegramBot\Commands\SystemCommand; 13 | use Longman\TelegramBot\Request; 14 | 15 | /** 16 | * Callback query command 17 | */ 18 | class CallbackqueryCommand extends SystemCommand 19 | { 20 | /**#@+ 21 | * {@inheritdoc} 22 | */ 23 | protected $name = 'callbackquery'; 24 | protected $description = 'Reply to callback query'; 25 | protected $version = '1.0.0'; 26 | /**#@-*/ 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function execute() 32 | { 33 | $update = $this->getUpdate(); 34 | $callback_query = $update->getCallbackQuery(); 35 | $callback_query_id = $callback_query->getId(); 36 | $callback_data = $callback_query->getData(); 37 | 38 | $data['callback_query_id'] = $callback_query_id; 39 | 40 | if ($callback_data == 'thumb up') { 41 | $data['text'] = 'Hello World!'; 42 | $data['show_alert'] = true; 43 | } else { 44 | $data['text'] = 'Hello World!'; 45 | $data['show_alert'] = false; 46 | } 47 | 48 | return Request::answerCallbackQuery($data); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_chosen_inline_result.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramChosenInlineResult extends Migration 15 | { 16 | public function down() 17 | { 18 | Schema::drop('theone74_telegram_chosen_inline_result'); 19 | } 20 | 21 | public function up() 22 | { 23 | Schema::create('theone74_telegram_chosen_inline_result', function($table) 24 | { 25 | $table->engine = 'InnoDB'; 26 | $table->bigIncrements('id'); 27 | $table->bigInteger('user_id')->nullable(); 28 | $table->string('result_id', 255)->default(''); 29 | $table->string('location', 255)->nullable()->default(null); 30 | $table->string('inline_message_id', 255)->nullable()->default(null); 31 | $table->text('query')->default(''); 32 | $table->timestamp('created_at')->nullable()->default(null); 33 | 34 | $table->index(['user_id'], 'user_id'); 35 | 36 | $table->foreign('user_id') 37 | ->references('id') 38 | ->on('theone74_telegram_user'); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /controllers/chats/_send_modal.htm: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 33 | -------------------------------------------------------------------------------- /commands/SystemCommands/GenericCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | use Longman\TelegramBot\Request; 13 | 14 | /** 15 | * Generic command 16 | */ 17 | class GenericCommand extends SystemCommand 18 | { 19 | /**#@+ 20 | * {@inheritdoc} 21 | */ 22 | protected $name = 'Generic'; 23 | protected $description = 'Handles generic commands or is executed by default when a command is not found'; 24 | protected $version = '1.0.1'; 25 | /**#@-*/ 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function execute() 31 | { 32 | $message = $this->getMessage(); 33 | 34 | //You can use $command as param 35 | $chat_id = $message->getChat()->getId(); 36 | $user_id = $message->getFrom()->getId(); 37 | $command = $message->getCommand(); 38 | 39 | if (in_array($user_id, $this->telegram->getAdminList()) && strtolower(substr($command, 0, 5)) == 'whois') { 40 | return $this->telegram->executeCommand('whois', $this->update); 41 | } 42 | 43 | $data = [ 44 | 'chat_id' => $chat_id, 45 | 'text' => 'Command /' . $command . ' not found.. :(', 46 | ]; 47 | 48 | return Request::sendMessage($data); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /updates/fix_callback_query.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class FixCallbackQuery extends Migration 15 | { 16 | 17 | public function down() 18 | { 19 | Schema::table('theone74_telegram_callback_query', function($table) 20 | { 21 | $table->dropForeign('theone74_telegram_callback_query_chat_id_foreign'); 22 | 23 | $table->dropIndex('chat_id'); 24 | $table->dropIndex('message_id'); 25 | 26 | $table->dropColumn('chat_id'); 27 | $table->dropColumn('message_id'); 28 | 29 | $table->text('message')->nullable()->default(null); 30 | }); 31 | } 32 | 33 | public function up() 34 | { 35 | Schema::table('theone74_telegram_callback_query', function($table) 36 | { 37 | $table->bigInteger('chat_id')->nullable(); 38 | $table->bigInteger('message_id')->unsigned()->nullable()->default(null); 39 | $table->dropColumn('message'); 40 | // $table->text('message')->nullable()->default(null); 41 | 42 | $table->index(['chat_id'], 'chat_id'); 43 | $table->index(['message_id'], 'message_id'); 44 | 45 | $table->foreign('chat_id') 46 | ->references('id') 47 | ->on('theone74_telegram_chat'); 48 | }); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /formwidgets/checkwebhook/partials/_wnd.htm: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /formwidgets/TelegramChat.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Backend\Classes\FormWidgetBase; 12 | use TheOne74\Telegram\Models\Chat; 13 | 14 | /** 15 | * Backend form widget for select chat 16 | */ 17 | class TelegramChat extends FormWidgetBase 18 | { 19 | protected $defaultAlias = 'telechat'; 20 | 21 | public function widgetDetails() 22 | { 23 | return [ 24 | 'name' => 'Telegram Chat', 25 | 'description' => 'Renders a chat selector field.' 26 | ]; 27 | } 28 | 29 | public function init() 30 | { 31 | parent::init(); 32 | } 33 | 34 | public function render() { 35 | $this->getChatsInfo(); 36 | $this->vars['field'] = $this->formField; 37 | return $this->makePartial('body', ['field' => $this->vars['field']]); 38 | } 39 | 40 | public function getChatsInfo() { 41 | $res = []; 42 | $chats = Chat::all(); 43 | foreach ($chats as $k => $v) { 44 | $res[$v->id] = $v->listTitle; 45 | // switch ($v->type) { 46 | // case 'private': 47 | // $res[$v->id] = sprintf('"%s" private chat', $v->user[0]->username); 48 | // break; 49 | // case 'group': 50 | // $res[$v->id] = sprintf('"%s" group chat', $v->title); 51 | // break; 52 | // } 53 | } 54 | $this->vars['fieldOptions'] = $res; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This plugin allows you to integrate functions of Telegram bots to your website and send data to users, groups or channels. 2 | 3 | Big thanks to 4 | * Longman https://github.com/akalongman/php-telegram-bot 5 | * Yurasov Max (aka Diz) 6 | 7 | 8 | Applications: 9 | * Make important notifications about site events to your Telegram application (desktop and mobile devices) 10 | * Receive messages and command from users and answer them 11 | * Send messages to groups, chat rooms, channels (like news or some kind of information or statistic) 12 | * Show keyboard, built-in keyboard 13 | * All list in the [official doc](https://core.telegram.org/bots#1-what-can-i-do-with-bots) 14 | 15 | 16 | ### Create bot 17 | 18 | Follow this [steps](https://core.telegram.org/bots#6-botfather) to create bot and receive token. 19 | 20 | ### Configure plugin 21 | 22 | * (required) Set Telegram token 23 | * (required) Set bot name 24 | * (required) Set webhook checkbox, it enables receive message from Telegram. 25 | * (optional) Db encoding. Select your db encoding. 26 | * (optional) Set certificate path if you use self-signed ssl certificate. 27 | * (optional) Select admin users. (example) 28 | * (optional) [Botan.io analitycs](http://botan.io) 29 | 30 | ### Simple notifications 31 | 32 | Use plugin to send notification over telegram. To do that: 33 | 34 | * Configure telegram bot account in the backend panel, go to Settings -> Telegram -> Bot settings 35 | * Add at the top of your controller or page code `use \TheOne74\Telegram\Classes\TelegramApi;` 36 | * Get your `chat_id` from Telegram -> Chats 37 | * Send message with 38 | ``` 39 | TelegramApi::instance()->sendMessage(['chat_id'=>chat_id, 'text'=>'new order was submitted']); 40 | ``` 41 | 42 | ### Create bot behaviour 43 | 44 | To be coninued 45 | -------------------------------------------------------------------------------- /controllers/Chats.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Backend\Classes\Controller; 12 | use BackendMenu; 13 | use TheOne74\Telegram\Classes\TelegramApi; 14 | use \Longman\TelegramBot\Request; 15 | use \Longman\TelegramBot\Exception\TelegramException; 16 | use \TheOne74\Telegram\Models\TelegramInfoSettings; 17 | 18 | class Chats extends Controller 19 | { 20 | public $implement = ['Backend\Behaviors\ListController']; 21 | public $requiredPermissions = ['theone74.telegram.show.chats']; 22 | 23 | public $listConfig = 'config_list.yaml'; 24 | 25 | public function __construct() 26 | { 27 | parent::__construct(); 28 | BackendMenu::setContext('TheOne74.Telegram', 'main-menu-item', 'side-menu-item3'); 29 | } 30 | 31 | public function onLoadSendWindow() { 32 | 33 | $this->vars['chat_id'] = intval(post('chat_id')); 34 | 35 | return $this->makePartial('send_modal'); 36 | } 37 | 38 | public function onSend() { 39 | if ( ! $this->user->hasPermission('theone74.telegram.send')) { 40 | throw new \Exception('No permissions'); 41 | } 42 | $chat_id = post('chat_id'); 43 | $text = post('text'); 44 | $telegram = TelegramApi::instance(); 45 | $result = Request::sendMessage(['chat_id' => $chat_id, 'text' => $text]); 46 | if ($result->isOk()) { 47 | \Flash::success($result->getDescription()); 48 | } 49 | return ;// $result->getResult()->getMessageId(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /commands/SystemCommands/GenericmessageCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Conversation; 12 | use Longman\TelegramBot\Request; 13 | use Longman\TelegramBot\Commands\SystemCommand; 14 | 15 | /** 16 | * Generic message command 17 | */ 18 | class GenericmessageCommand extends SystemCommand 19 | { 20 | /**#@+ 21 | * {@inheritdoc} 22 | */ 23 | protected $name = 'Genericmessage'; 24 | protected $description = 'Handle generic message'; 25 | protected $version = '1.0.2'; 26 | protected $need_mysql = true; 27 | /**#@-*/ 28 | 29 | /** 30 | * Execution if MySQL is required but not available 31 | * 32 | * @return boolean 33 | */ 34 | public function executeNoDb() 35 | { 36 | //Do nothing 37 | return Request::emptyResponse(); 38 | } 39 | 40 | /** 41 | * Execute command 42 | * 43 | * @return boolean 44 | */ 45 | public function execute() 46 | { 47 | //If a conversation is busy, execute the conversation command after handling the message 48 | $conversation = new Conversation( 49 | $this->getMessage()->getFrom()->getId(), 50 | $this->getMessage()->getChat()->getId() 51 | ); 52 | //Fetch conversation command if it exists and execute it 53 | if ($conversation->exists() && ($command = $conversation->getCommand())) { 54 | return $this->telegram->executeCommand($command, $this->update); 55 | } 56 | 57 | return Request::emptyResponse(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_conversation.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramConversation extends Migration 15 | { 16 | public function up() 17 | { 18 | Schema::create('theone74_telegram_conversation', function($table) 19 | { 20 | $table->engine = 'InnoDB'; 21 | $table->bigIncrements('id')->unsigned(); 22 | $table->bigInteger('user_id')->nullable()->default(null); 23 | $table->bigInteger('chat_id')->nullable()->default(null); 24 | $table->enum('status', ['active', 'cancelled', 'stopped'])->default('active'); 25 | $table->string('command', 160)->default(''); 26 | $table->string('notes', 1000)->default('NULL'); 27 | $table->timestamp('created_at')->nullable()->default(null); 28 | $table->timestamp('updated_at')->nullable()->default(null); 29 | 30 | $table->index(['user_id'], 'user_id'); 31 | $table->index(['chat_id'], 'chat_id'); 32 | $table->index(['status'], 'status'); 33 | 34 | $table->foreign('user_id') 35 | ->references('id') 36 | ->on('theone74_telegram_user'); 37 | 38 | $table->foreign('chat_id') 39 | ->references('id') 40 | ->on('theone74_telegram_chat'); 41 | }); 42 | } 43 | 44 | public function down() 45 | { 46 | Schema::drop('theone74_telegram_conversation'); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /classes/RegisterWidgets.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Lang; 12 | use RainLab\Builder\Classes\ControlLibrary; 13 | 14 | class RegisterWidgets { 15 | 16 | protected $controlLibrary; 17 | 18 | public function __construct($controlLibrary) 19 | { 20 | $this->controlLibrary = $controlLibrary; 21 | 22 | $this->registerControls(); 23 | } 24 | 25 | protected function registerControls() 26 | { 27 | $properties = [ 28 | // 'options' => [ 29 | // 'title' => Lang::get('rainlab.builder::lang.form.property_options'), 30 | // 'type' => 'dictionary', 31 | // 'ignoreIfEmpty' => true, 32 | // 'sortOrder' => 81 33 | // ], 34 | // 'form' => [ 35 | // 'type' => 'control-container' 36 | // ] 37 | ]; 38 | 39 | $ignoreProperties = [ 40 | // 'stretch', 41 | // 'placeholder', 42 | // 'default', 43 | // 'required', 44 | // 'defaultFrom', 45 | // 'dependsOn', 46 | // 'trigger', 47 | // 'preset', 48 | // 'attributes' 49 | ]; 50 | 51 | $this->controlLibrary->registerControl('telechat', 52 | 'Telegram Chat', 53 | 'Renders a chat selector field.', 54 | ControlLibrary::GROUP_WIDGETS, 55 | 'icon-paper-plane-o', 56 | $this->controlLibrary->getStandardProperties($ignoreProperties, $properties), 57 | 'TheOne74\Telegram\Classes\WidgetDesignTimeProvider' 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_edited_message.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramEditedMessage extends Migration 15 | { 16 | 17 | public function down() 18 | { 19 | Schema::drop('theone74_telegram_edited_message'); 20 | } 21 | 22 | public function up() 23 | { 24 | Schema::create('theone74_telegram_edited_message', function($table) 25 | { 26 | $table->engine = 'InnoDB'; 27 | $table->bigIncrements('id')->unsigned(); 28 | $table->bigInteger('chat_id'); 29 | $table->bigInteger('message_id')->unsigned(); 30 | $table->bigInteger('user_id')->nullable(); 31 | $table->dateTime('edit_date')->nullable()->default(null); 32 | $table->text('text')->nullable()->default(null); 33 | $table->text('entities')->nullable()->default(null); 34 | $table->text('caption')->nullable()->default(null); 35 | 36 | $table->index(['chat_id'], 'chat_id'); 37 | $table->index(['message_id'], 'message_id'); 38 | $table->index(['user_id'], 'user_id'); 39 | 40 | $table->foreign('user_id') 41 | ->references('id') 42 | ->on('theone74_telegram_user'); 43 | 44 | $table->foreign('chat_id') 45 | ->references('id') 46 | ->on('theone74_telegram_chat'); 47 | 48 | $table->foreign(['chat_id', 'message_id']) 49 | ->references(['chat_id', 'id']) 50 | ->on('theone74_telegram_message'); 51 | }); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Plugin.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use System\Classes\PluginBase; 12 | use TheOne74\Telegram\Classes\RegisterWidgets; 13 | 14 | class Plugin extends PluginBase 15 | { 16 | public function registerComponents() 17 | { 18 | } 19 | 20 | public function registerSettings() 21 | { 22 | return [ 23 | 'settings' => [ 24 | 'label' => 'theone74.telegram::lang.settings.page_name', 25 | 'description' => 'theone74.telegram::lang.settings.page_desc', 26 | 'category' => 'theone74.telegram::lang.plugin.name', 27 | 'icon' => 'icon-paper-plane', 28 | 'class' => 'TheOne74\Telegram\Models\TelegramInfoSettings', 29 | 'order' => 500, 30 | 'keywords' => 'telegram bot', 31 | 'permissions' => ['theone74.telegram.settings'] 32 | ] 33 | ]; 34 | } 35 | 36 | public function registerFormWidgets() 37 | { 38 | return [ 39 | 'TheOne74\Telegram\FormWidgets\TelegramChat' => [ 40 | 'label' => 'Telegram Chat', 41 | 'code' => 'telechat', 42 | 'alias' => 'telechat', 43 | ], 44 | 'TheOne74\Telegram\FormWidgets\CheckWebhook' => [ 45 | 'label' => 'Telegram check webhook button', 46 | 'code' => 'checkwebhook', 47 | 'alias' => 'checkwebhook', 48 | ], 49 | ]; 50 | } 51 | 52 | public function boot() { 53 | \Event::listen('pages.builder.registerControls', function($controlLibrary) { 54 | new RegisterWidgets($controlLibrary); 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /plugin.yaml: -------------------------------------------------------------------------------- 1 | plugin: 2 | name: 'theone74.telegram::lang.plugin.name' 3 | description: 'theone74.telegram::lang.plugin.description' 4 | author: 'Anton R' 5 | icon: icon-paper-plane-o 6 | homepage: '' 7 | navigation: 8 | main-menu-item: 9 | label: 'theone74.telegram::lang.plugin.name' 10 | url: theone74/telegram/users 11 | icon: icon-paper-plane 12 | permissions: 13 | - theone74.telegram.show 14 | sideMenu: 15 | side-menu-item: 16 | label: 'theone74.telegram::lang.left_menu.users' 17 | url: theone74/telegram/users 18 | icon: icon-user 19 | permissions: 20 | - theone74.telegram.show.users 21 | side-menu-item2: 22 | label: 'theone74.telegram::lang.left_menu.messages' 23 | url: theone74/telegram/messages 24 | icon: icon-file-text 25 | permissions: 26 | - theone74.telegram.show.messages 27 | side-menu-item3: 28 | label: 'theone74.telegram::lang.left_menu.chats' 29 | url: theone74/telegram/chats 30 | icon: icon-comments 31 | permissions: 32 | - theone74.telegram.show.chats 33 | permissions: 34 | theone74.telegram.show.users: 35 | tab: 'theone74.telegram::lang.plugin.name' 36 | label: 'Show users' 37 | theone74.telegram.show.chats: 38 | tab: 'theone74.telegram::lang.plugin.name' 39 | label: 'Show chats' 40 | theone74.telegram.show.messages: 41 | tab: 'theone74.telegram::lang.plugin.name' 42 | label: 'Show messages' 43 | theone74.telegram.show: 44 | tab: 'theone74.telegram::lang.plugin.name' 45 | label: 'Show plugin' 46 | theone74.telegram.send: 47 | tab: 'theone74.telegram::lang.plugin.name' 48 | label: 'Send messages' 49 | theone74.telegram.settings: 50 | tab: 'theone74.telegram::lang.plugin.name' 51 | label: 'Manage settings' 52 | -------------------------------------------------------------------------------- /plot/config-snippets1.gnu: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/gnuplot 2 | # 3 | # Plot bessel functions and highlight use of config files 4 | # 5 | # AUTHOR: Hagen Wierstorf 6 | # gnuplot 4.6 patchlevel 6 7 | 8 | reset 9 | 10 | # wxt 11 | # set terminal wxt size 700,524 enhanced font 'Verdana,16' persist 12 | # png 13 | set terminal pngcairo size 700,524 enhanced font 'Verdana,16' 14 | set output 'config-snippets1.png' 15 | 16 | # set path of config snippets 17 | #set loadpath './config' 18 | # load config snippets 19 | load 'dark2.pal' 20 | load 'xyborder.cfg' 21 | load 'grid.cfg' 22 | # load 'mathematics.cfg' 23 | 24 | # set xrange [0:15] 25 | # unset key 26 | set title 'Hello, world' 27 | # set xlabel 'Time' 28 | # set ylabel 'Visits' 29 | # set key top right 30 | set key box lc rgb "#e6e7e9" 31 | set key horizontal 32 | set key center bottom 33 | set key bmargin 34 | # set key 0.01,100 35 | set bmargin 4 36 | set xtics rotate by 45 offset -3.0,-1.5 37 | 38 | set key font ",14" 39 | set tic font ',14' 40 | set ylabel font ',14' 41 | set title font ',18' 42 | 43 | # set label 'J_0' at 1.4,0.90 center tc ls 1 44 | # set label 'J_1' at 1.9,0.67 center tc ls 2 45 | # set label 'J_2' at 3.2,0.57 center tc ls 3 46 | # set label 'J_3' at 4.3,0.51 center tc ls 4 47 | # set label 'J_4' at 5.4,0.48 center tc ls 5 48 | # set label 'J_5' at 6.5,0.45 center tc ls 6 49 | # set label 'J_6' at 7.6,0.43 center tc ls 7 50 | 51 | # plot besj0(x) ls 1 lw 2, \ 52 | # besj1(x) ls 2 lw 2, \ 53 | # besj2(x) ls 3 lw 2, \ 54 | # besj3(x) ls 4 lw 2, \ 55 | # besj4(x) ls 5 lw 2, \ 56 | # besj5(x) ls 6 lw 2, \ 57 | # besj6(x) ls 7 lw 2 58 | # set xdata time 59 | # set autoscale x 60 | # set xrange ["1901-01-01 16:00":"2016-07-22 16:00"] 61 | 62 | # set timefmt '%Y%m%d' 63 | # set xdata time 64 | # set format x '%Y%m%d' 65 | 66 | # set multiplot layout 1,2 67 | 68 | set label 1 "site.name" at graph 0.05, graph 0.9 font ",18" tc rgb "#969696" 69 | 70 | 71 | $data < 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | use Longman\TelegramBot\Commands\SystemCommand; 12 | use Longman\TelegramBot\Entities\InlineQueryResultArticle; 13 | use Longman\TelegramBot\Entities\InputTextMessageContent; 14 | use Longman\TelegramBot\Request; 15 | 16 | /** 17 | * Inline query command 18 | */ 19 | class InlinequeryCommand extends SystemCommand 20 | { 21 | /**#@+ 22 | * {@inheritdoc} 23 | */ 24 | protected $name = 'inlinequery'; 25 | protected $description = 'Reply to inline query'; 26 | protected $version = '1.0.1'; 27 | /**#@-*/ 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | public function execute() 33 | { 34 | $update = $this->getUpdate(); 35 | $inline_query = $update->getInlineQuery(); 36 | $query = $inline_query->getQuery(); 37 | 38 | $data = ['inline_query_id' => $inline_query->getId()]; 39 | 40 | $articles = [ 41 | ['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])], 42 | ['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])], 43 | ['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query , 'input_message_content' => new InputTextMessageContent([ 'message_text' => ' ' . $query ])], 44 | ]; 45 | 46 | $array_article = []; 47 | foreach ($articles as $article) { 48 | $array_article[] = new InlineQueryResultArticle($article); 49 | } 50 | $data['results'] = '[' . implode(',', $array_article) . ']'; 51 | 52 | return Request::answerInlineQuery($data); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lang/en/lang.php: -------------------------------------------------------------------------------- 1 | [ 3 | 'name' => 'Telegram', 4 | 'description' => '' 5 | ], 6 | 'left_menu' => [ 7 | 'users' =>'Users', 8 | 'messages' => 'Messages', 9 | 'chats' => 'Chats' 10 | ], 11 | 'lists' => [ 12 | 'id' => 'ID', 13 | 'type' => 'Type', 14 | 'title' => 'Group title', 15 | 'username' => 'Username', 16 | 'control' => '', 17 | 'name' => 'Name', 18 | 'chat' => 'Chat', 19 | 'text' => 'Text', 20 | 'date' => 'Date', 21 | 'created_at' => 'Created at', 22 | 'updated_at' => 'Updated at', 23 | 24 | ], 25 | 'chats' => [ 26 | 'send_message' => 'Send message', 27 | ], 28 | 'send_msg_wnd' => [ 29 | 'caption' => 'Send message', 30 | 'placeholder' => 'Enter message text...', 31 | 'ok' => 'Send', 32 | 'cancel' => 'Cancel', 33 | 'confirm' => 'Are you sure?', 34 | ], 35 | 'users' => [ 36 | 37 | ], 38 | 'settings' => [ 39 | 'page_name' => 'Bot settings', 40 | 'page_desc' => 'Manage bot settings', 41 | 'bot_token' => 'Bot token', 42 | 'bot_name' => 'Bot name', 43 | 'cert_path' => 'Certificate file path (*.crt)', 44 | 'use_webhook' => 'Use webhook?', 45 | 'is_selfsigned' => 'Self signed certificate?', 46 | 'bot_tab' => 'Bot config', 47 | 'admin_tab' => 'Admins', 48 | 'admins_ids' => 'Admins', 49 | 'user_id' => 'Admin', 50 | 'add_new_admin' => 'Add new admin', 51 | 'db_encoding' => 'Db encoding', 52 | 'db_encoding_utf8' => 'utf8 (Default)', 53 | 'db_encoding_utf8mb4' => 'utf8mb4', 54 | 'botan_token' => 'Botan.io token', 55 | 'botan_tab' => 'Botan.io', 56 | 'botan_placeholder' => 'GAX8YDgkVzXJrFmTbf1vXU34bD_rZUB7', 57 | 'btn_test_web_hook' => 'Test webhook', 58 | 'lbl_test_web_hook' => 'Test webhook', 59 | 60 | 'wnd' => [ 61 | 'title' => 'Webhook info', 62 | 'url' => 'url', 63 | 'has_custom_certificate' => 'Has custom certificate', 64 | 'pending_update_count' => 'Pending update count', 65 | 'last_error_date' => 'Last error date', 66 | 'last_error_message' => 'Last error message', 67 | 'ok' => 'ok', 68 | ] 69 | ], 70 | 'error' => [ 71 | 'cert_path_required' => '"Certificate file path" field is required.' 72 | ], 73 | ]; 74 | -------------------------------------------------------------------------------- /lang/ru/lang.php: -------------------------------------------------------------------------------- 1 | [ 3 | 'name' => 'Телеграф', 4 | 'description' => '' 5 | ], 6 | 'left_menu' => [ 7 | 'users' =>'Пользователи', 8 | 'messages' => 'Сообщения', 9 | 'chats' => 'Чаты' 10 | ], 11 | 'lists' => [ 12 | 'id' => '#', 13 | 'type' => 'Тип', 14 | 'title' => 'Заголовок', 15 | 'username' => 'Пользователь', 16 | 'control' => '', 17 | 'name' => 'Имя', 18 | 'chat' => 'Чат', 19 | 'text' => 'Текст', 20 | 'date' => 'Дата', 21 | 'created_at' => 'Создан', 22 | 'updated_at' => 'Обновлен', 23 | ], 24 | 'chats' => [ 25 | 'send_message' => 'Написать сообщение', 26 | ], 27 | 'send_msg_wnd' => [ 28 | 'caption' => 'Написать сообщение', 29 | 'placeholder' => 'Введите текст...', 30 | 'ok' => 'Отправить', 31 | 'cancel' => 'Отмена', 32 | 'confirm' => 'Вы уверены?', 33 | ], 34 | 'users' => [ 35 | 36 | ], 37 | 'settings' => [ 38 | 'page_name' => 'Настройки бота', 39 | 'page_desc' => 'Настройки бота', 40 | 'bot_token' => 'Токен', 41 | 'bot_name' => 'Имя бота', 42 | 'cert_path' => 'Путь к файлу сертификата (*.crt)', 43 | 'use_webhook' => 'Использовать webhook', 44 | 'is_selfsigned' => 'Самоподписанный сертификат?', 45 | 'bot_tab' => 'Настройки бота', 46 | 'admin_tab' => 'Администраторы бота', 47 | 'admins_ids' => 'Администраторы', 48 | 'user_id' => 'Админ', 49 | 'add_new_admin' => 'Добавить нового администратора', 50 | 'db_encoding' => 'Кодировка базы данных', 51 | 'db_encoding_utf8' => 'utf8 (Default)', 52 | 'db_encoding_utf8mb4' => 'utf8mb4', 53 | 'botan_token' => 'Botan.io токен', 54 | 'botan_tab' => 'Botan.io', 55 | 'botan_placeholder' => 'GAX8YDgkVzXJrFmTbf1vXU34bD_rZUB7', 56 | 'btn_test_web_hook' => 'Test webhook', 57 | 'lbl_test_web_hook' => 'Test webhook', 58 | 59 | 'wnd' => [ 60 | 'title' => 'Webhook info', 61 | 'url' => 'url', 62 | 'has_custom_certificate' => 'Has custom certificate', 63 | 'pending_update_count' => 'Pending update count', 64 | 'last_error_date' => 'Last error date', 65 | 'last_error_message' => 'Last error message', 66 | 'ok' => 'ok', 67 | ] 68 | ], 69 | 'error' => [ 70 | 'cert_path_required' => 'Необходимо заполнить "Certificate file path".' 71 | ], 72 | ]; 73 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_telegram_update.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramTelegramUpdate extends Migration 15 | { 16 | public function down() 17 | { 18 | Schema::drop('theone74_telegram_telegram_update'); 19 | } 20 | 21 | public function up() 22 | { 23 | Schema::create('theone74_telegram_telegram_update', function($table) 24 | { 25 | $table->engine = 'InnoDB'; 26 | $table->bigIncrements('id')->unsigned(); 27 | $table->bigInteger('chat_id')->nullable()->default(null); 28 | $table->bigInteger('message_id')->unsigned()->nullable()->default(null); 29 | $table->bigInteger('inline_query_id')->unsigned()->nullable()->default(null); 30 | $table->bigInteger('chosen_inline_result_id')->unsigned()->nullable()->default(null); 31 | $table->bigInteger('callback_query_id')->unsigned()->nullable()->default(null); 32 | $table->bigInteger('edited_message_id')->unsigned()->nullable()->default(null); 33 | 34 | $table->index(['chat_id', 'message_id'], 'message_id'); 35 | $table->index(['inline_query_id'], 'inline_query_id'); 36 | $table->index(['chosen_inline_result_id'], 'chosen_inline_result_id'); 37 | $table->index(['callback_query_id'], 'callback_query_id'); 38 | $table->index(['edited_message_id'], 'edited_message_id'); 39 | 40 | $table->foreign(['chat_id', 'message_id']) 41 | ->references(['chat_id', 'id']) 42 | ->on('theone74_telegram_message'); 43 | 44 | $table->foreign('inline_query_id') 45 | ->references('id') 46 | ->on('theone74_telegram_inline_query'); 47 | 48 | $table->foreign('chosen_inline_result_id', 'chosen_inline_result_id') 49 | ->references('id') 50 | ->on('theone74_telegram_chosen_inline_result'); 51 | 52 | $table->foreign('callback_query_id') 53 | ->references('id') 54 | ->on('theone74_telegram_callback_query'); 55 | 56 | $table->foreign('edited_message_id') 57 | ->references('id') 58 | ->on('theone74_telegram_edited_message'); 59 | 60 | }); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /commands/UserCommands/HelpCommand.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | 12 | use Longman\TelegramBot\Commands\UserCommand; 13 | use Longman\TelegramBot\Request; 14 | 15 | /** 16 | * User "/help" command 17 | */ 18 | class HelpCommand extends UserCommand 19 | { 20 | /**#@+ 21 | * {@inheritdoc} 22 | */ 23 | protected $name = 'help'; 24 | protected $description = 'Show bot commands help'; 25 | protected $usage = '/help or /help '; 26 | protected $version = '1.0.1'; 27 | /**#@-*/ 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | public function execute() 33 | { 34 | $message = $this->getMessage(); 35 | $chat_id = $message->getChat()->getId(); 36 | 37 | $message_id = $message->getMessageId(); 38 | $command = trim($message->getText(true)); 39 | 40 | //Only get enabled Admin and User commands 41 | $commands = array_filter($this->telegram->getCommandsList(), function ($command) { 42 | return (!$command->isSystemCommand() && $command->isEnabled()); 43 | }); 44 | 45 | //If no command parameter is passed, show the list 46 | if ($command === '') { 47 | $text = $this->telegram->getBotName() . ' v. ' . $this->telegram->getVersion() . "\n\n"; 48 | $text .= 'Commands List:' . "\n"; 49 | foreach ($commands as $command) { 50 | $text .= '/' . $command->getName() . ' - ' . $command->getDescription() . "\n"; 51 | } 52 | 53 | $text .= "\n" . 'For exact command help type: /help '; 54 | } else { 55 | $command = str_replace('/', '', $command); 56 | if (isset($commands[$command])) { 57 | $command = $commands[$command]; 58 | $text = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n"; 59 | $text .= 'Description: ' . $command->getDescription() . "\n"; 60 | $text .= 'Usage: ' . $command->getUsage(); 61 | } else { 62 | $text = 'No help available: Command /' . $command . ' not found'; 63 | } 64 | } 65 | 66 | $data = [ 67 | 'chat_id' => $chat_id, 68 | 'reply_to_message_id' => $message_id, 69 | 'text' => $text, 70 | ]; 71 | 72 | return Request::sendMessage($data); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /models/telegraminfosettings/fields.yaml: -------------------------------------------------------------------------------- 1 | fields: { } 2 | tabs: 3 | fields: 4 | token: 5 | label: 'theone74.telegram::lang.settings.bot_token' 6 | oc.commentPosition: '' 7 | span: auto 8 | placeholder: '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11' 9 | disabled: 0 10 | required: 1 11 | type: text 12 | tab: 'theone74.telegram::lang.settings.bot_tab' 13 | name: 14 | label: 'theone74.telegram::lang.settings.bot_name' 15 | oc.commentPosition: '' 16 | span: auto 17 | required: 1 18 | type: text 19 | tab: 'theone74.telegram::lang.settings.bot_tab' 20 | is_webhook: 21 | label: 'theone74.telegram::lang.settings.use_webhook' 22 | span: left 23 | default: 1 24 | type: checkbox 25 | tab: 'theone74.telegram::lang.settings.bot_tab' 26 | is_selfsigned: 27 | label: 'theone74.telegram::lang.settings.is_selfsigned' 28 | span: right 29 | trigger: 30 | action: disable 31 | field: is_webhook 32 | condition: unchecked 33 | default: 0 34 | type: checkbox 35 | tab: 'theone74.telegram::lang.settings.bot_tab' 36 | cert_path: 37 | label: 'theone74.telegram::lang.settings.cert_path' 38 | oc.commentPosition: '' 39 | span: right 40 | trigger: 41 | action: disable 42 | field: is_selfsigned 43 | condition: unchecked 44 | type: text 45 | tab: 'theone74.telegram::lang.settings.bot_tab' 46 | db_encoding: 47 | label: 'theone74.telegram::lang.settings.db_encoding' 48 | type: dropdown 49 | default: utf8 50 | span: left 51 | options: 52 | utf8: 'theone74.telegram::lang.settings.db_encoding_utf8' 53 | utf8mb4: 'theone74.telegram::lang.settings.db_encoding_utf8mb4' 54 | tab: 'theone74.telegram::lang.settings.bot_tab' 55 | check_web_hook: 56 | label: 'theone74.telegram::lang.settings.lbl_test_web_hook' 57 | type: checkwebhook 58 | tab: 'theone74.telegram::lang.settings.bot_tab' 59 | 60 | admins: 61 | label: 'theone74.telegram::lang.settings.admins_ids' 62 | type: repeater 63 | tab: 'theone74.telegram::lang.settings.admin_tab' 64 | span: left 65 | prompt: 'theone74.telegram::lang.settings.add_new_admin' 66 | form: 67 | fields: 68 | admin: 69 | label: 'theone74.telegram::lang.settings.user_id' 70 | type: dropdown 71 | 72 | botan_token: 73 | label: 'theone74.telegram::lang.settings.botan_token' 74 | oc.commentPosition: '' 75 | commentHtml: 1 76 | comment: 'Use @Botaniobot to generate token and get analytics' 77 | span: auto 78 | placeholder: 'theone74.telegram::lang.settings.botan_placeholder' 79 | disabled: 0 80 | required: 0 81 | type: text 82 | tab: 'theone74.telegram::lang.settings.botan_tab' 83 | -------------------------------------------------------------------------------- /models/TelegramInfoSettings.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Model; 12 | use Flash; 13 | use Config; 14 | use TheOne74\Telegram\Classes\TelegramApi; 15 | use TheOne74\Telegram\Models\User; 16 | 17 | /** 18 | * TelegramInfoSettings Model 19 | */ 20 | class TelegramInfoSettings extends Model 21 | { 22 | use \October\Rain\Database\Traits\Validation; 23 | 24 | public $implement = ['System.Behaviors.SettingsModel']; 25 | 26 | // A unique code 27 | public $settingsCode = 'theone74_telegram_info'; 28 | 29 | // Reference to field configuration 30 | public $settingsFields = 'fields.yaml'; 31 | 32 | public $rules = [ 33 | 'name' => 'required|between:1,16', 34 | 'is_webhook' => 'required|boolean', 35 | 'is_selfsigned' => 'required_with:is_webhook|boolean', 36 | 'cert_path' => 'required_with_all:is_webhook,is_selfsigned|string', 37 | 'token' => 'required|regex:/^[0-9]+:[a-z0-9\-_]+$/i' 38 | ]; 39 | 40 | public $customMessages = [ 41 | 'cert_path.required_with_all' => 'theone74.telegram::lang.error.cert_path_required' 42 | ]; 43 | 44 | function unparse_url($parsed_url) { 45 | $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; 46 | $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; 47 | $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; 48 | $user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; 49 | $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; 50 | $pass = ($user || $pass) ? "$pass@" : ''; 51 | $path = isset($parsed_url['path']) ? str_replace('//', '/', $parsed_url['path']) : ''; 52 | $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; 53 | $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; 54 | return "$scheme$user$pass$host$port$path$query$fragment"; 55 | } 56 | 57 | function afterSave() { 58 | 59 | $url = parse_url(Config::get('app.url')); 60 | $url['scheme'] = 'https'; 61 | $url['path'] .= '/telehook/'.$this->get('token'); 62 | $url = $this->unparse_url($url); 63 | 64 | $telegram = new TelegramApi($this->get('token'), $this->get('name')); 65 | 66 | if ($this->get('is_webhook')) { 67 | if ($this->get('is_selfsigned')) { 68 | $result = $telegram->setWebHook($url, $this->get('cert_path')); 69 | } 70 | else { 71 | $result = $telegram->setWebHook($url); 72 | } 73 | if ($result->isOk()) { 74 | Flash::success($result->getDescription()); 75 | } 76 | } 77 | else { 78 | $result = $telegram->unsetWebHook(); 79 | if ($result->isOk()) { 80 | Flash::success($result->getDescription()); 81 | } 82 | } 83 | } 84 | 85 | public function beforeValidate() 86 | { 87 | // $this->rules['admins'] = 'required'; 88 | // if you want the repeater to have at least one productItem 89 | foreach ($this->admins as $index => $Item) { 90 | $this->rules['admins.'.$index.'.admin'] = 'integer'; 91 | $this->customMessages['admins.'.$index.'.admin.integer'] = 'Admin number '.$index.' needs to be a integer.'; 92 | } 93 | } 94 | 95 | public function getAdminOptions() 96 | { 97 | User::all()->lists('username', 'id'); 98 | return User::all()->lists('username', 'id'); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /classes/TelegramApi.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use \TheOne74\Telegram\Models\TelegramInfoSettings; 12 | use \Longman\TelegramBot\Exception\TelegramException; 13 | use \Longman\TelegramBot\Request; 14 | 15 | class TelegramApi 16 | extends \Longman\TelegramBot\Telegram 17 | { 18 | 19 | public static $_instance; 20 | public static $_encoding = 'utf8'; 21 | protected $commands_namespaces = []; 22 | 23 | public function __construct($api_key, $bot_name) 24 | { 25 | parent::__construct($api_key, $bot_name); 26 | $this->addCommandsPathMy(plugins_path('theone74/telegram/commands'), 'TheOne74\\Telegram\\Commands'); 27 | if ((TelegramInfoSettings::instance()->get('db_encoding'))) { 28 | self::$_encoding = TelegramInfoSettings::instance()->get('db_encoding'); 29 | } 30 | } 31 | 32 | public function addCommandsPath($path, $before = true) {/* dummy */} 33 | 34 | public function addCommandsPathMy($path, $namespace, $before = true) 35 | { 36 | if (!is_dir($path)) { 37 | throw new TelegramException('Commands path "' . $path . '" does not exist!'); 38 | } 39 | if (!in_array($path, $this->commands_paths)) { 40 | if ($before) { 41 | array_unshift($this->commands_paths, $path); 42 | } else { 43 | array_push($this->commands_paths, $path); 44 | } 45 | } 46 | if (!in_array($namespace, $this->commands_namespaces)) { 47 | if ($before) { 48 | array_unshift($this->commands_namespaces, $namespace); 49 | } else { 50 | array_push($this->commands_namespaces, $namespace); 51 | } 52 | } 53 | return $this; 54 | } 55 | 56 | public function getCommandObject($command) 57 | { 58 | $which = ['System']; 59 | ($this->isAdmin()) && $which[] = 'Admin'; 60 | $which[] = 'User'; 61 | 62 | $command = explode('_', $command); 63 | $command = array_map(array($this, 'ucfirstUnicode'), $command); 64 | $command = implode('', $command); 65 | 66 | foreach ($this->commands_namespaces as $namespace) { 67 | foreach ($which as $auth) { 68 | $command_namespace = $namespace . '\\' . $auth . 'Commands\\' . $command . 'Command'; 69 | if (class_exists($command_namespace)) { 70 | return new $command_namespace($this, $this->update); 71 | } 72 | } 73 | } 74 | 75 | return null; 76 | } 77 | 78 | public static function instance(){ 79 | 80 | if ( ! self::$_instance) { 81 | if ( ! TelegramInfoSettings::instance()->get('token')) { 82 | throw new \Exception('Token not set'); 83 | } 84 | 85 | if ( ! TelegramInfoSettings::instance()->get('name')) { 86 | throw new \Exception('Bot name not set'); 87 | } 88 | 89 | self::$_instance = new TelegramApi( 90 | TelegramInfoSettings::instance()->get('token'), 91 | TelegramInfoSettings::instance()->get('name') 92 | ); 93 | 94 | $mysql_credentials = [ 95 | 'host' => \Config::get('database.connections.mysql.host'), 96 | 'database' => \Config::get('database.connections.mysql.database'), 97 | 'user' => \Config::get('database.connections.mysql.username'), 98 | 'password' => \Config::get('database.connections.mysql.password'), 99 | ]; 100 | // TODO 101 | self::$_instance->enableMySQL($mysql_credentials, 'theone74_telegram_', self::$_encoding); 102 | 103 | // batan.io 104 | if ($token = TelegramInfoSettings::instance()->get('botan_token')){ 105 | self::$_instance->enableBotan($token); 106 | } 107 | 108 | // enable admins 109 | $admins = []; 110 | foreach(TelegramInfoSettings::instance()->get('admins') as $i) { 111 | $admins[] = intval($i['admin']); 112 | } 113 | self::$_instance->enableAdmins($admins); 114 | } 115 | 116 | return self::$_instance; 117 | 118 | } 119 | 120 | public static function setDbEncoding($encoding) { 121 | self::$_encoding = $encoding; 122 | } 123 | 124 | public function sendMessage(array $data) { 125 | return Request::sendMessage($data); 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /updates/builder_table_create_theone74_telegram_message.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | 11 | use Schema; 12 | use October\Rain\Database\Updates\Migration; 13 | 14 | class BuilderTableCreateTheone74TelegramMessage extends Migration 15 | { 16 | 17 | public function down() 18 | { 19 | Schema::drop('theone74_telegram_message'); 20 | } 21 | 22 | public function up() 23 | { 24 | Schema::create('theone74_telegram_message', function($table) 25 | { 26 | $table->bigInteger('chat_id'); 27 | $table->bigInteger('id')->unsigned(); 28 | $table->bigInteger('user_id')->nullable(); 29 | $table->bigInteger('forward_from')->nullable()->default(null); 30 | $table->bigInteger('forward_from_chat')->nullable()->default(null); 31 | $table->bigInteger('reply_to_chat')->nullable()->default(null); 32 | $table->bigInteger('reply_to_message')->unsigned()->nullable()->default(null); 33 | $table->bigInteger('new_chat_member')->nullable()->default(null); 34 | $table->bigInteger('left_chat_member')->nullable()->default(null); 35 | $table->dateTime('date')->nullable()->default(null); 36 | $table->dateTime('forward_date')->nullable()->default(null); 37 | $table->text('text')->nullable()->default(null); 38 | $table->text('entities')->nullable()->default(null); 39 | $table->text('audio')->nullable()->default(null); 40 | $table->text('document')->nullable()->default(null); 41 | $table->text('photo')->nullable()->default(null); 42 | $table->text('sticker')->nullable()->default(null); 43 | $table->text('video')->nullable()->default(null); 44 | $table->text('voice')->nullable()->default(null); 45 | $table->text('contact')->nullable()->default(null); 46 | $table->text('location')->nullable()->default(null); 47 | $table->text('venue')->nullable()->default(null); 48 | $table->text('caption')->nullable()->default(null); 49 | $table->string('new_chat_title', 255)->nullable()->default(null); 50 | $table->text('new_chat_photo')->nullable()->default(null); 51 | $table->boolean('delete_chat_photo')->default(0); 52 | $table->boolean('group_chat_created')->default(0); 53 | $table->boolean('supergroup_chat_created')->default(0); 54 | $table->boolean('channel_chat_created')->default(0); 55 | $table->bigInteger('migrate_to_chat_id')->nullable()->default(null); 56 | $table->bigInteger('migrate_from_chat_id')->nullable()->default(null); 57 | $table->text('pinned_message')->nullable()->default(null); 58 | 59 | $table->primary(['chat_id', 'id']); 60 | $table->index(['user_id'], 'user_id'); 61 | $table->index(['forward_from'], 'forward_from'); 62 | $table->index(['forward_from_chat'], 'forward_from_chat'); 63 | $table->index(['reply_to_chat'], 'reply_to_chat'); 64 | $table->index(['reply_to_message'], 'reply_to_message'); 65 | $table->index(['new_chat_member'], 'new_chat_member'); 66 | $table->index(['left_chat_member'], 'left_chat_member'); 67 | $table->index(['migrate_from_chat_id'], 'migrate_from_chat_id'); 68 | $table->index(['migrate_to_chat_id'], 'migrate_to_chat_id'); 69 | 70 | $table->foreign('user_id') 71 | ->references('id') 72 | ->on('theone74_telegram_user'); 73 | 74 | $table->foreign('chat_id') 75 | ->references('id') 76 | ->on('theone74_telegram_chat'); 77 | 78 | $table->foreign('forward_from') 79 | ->references('id') 80 | ->on('theone74_telegram_user'); 81 | 82 | $table->foreign('forward_from_chat') 83 | ->references('id') 84 | ->on('theone74_telegram_chat'); 85 | 86 | $table->foreign(['reply_to_chat', 'reply_to_message']) 87 | ->references(['chat_id', 'id']) 88 | ->on('theone74_telegram_message'); 89 | 90 | // $table->foreign('forward_from') 91 | // ->references('id') 92 | // ->on('theone74_telegram_user'); 93 | 94 | $table->foreign('new_chat_member') 95 | ->references('id') 96 | ->on('theone74_telegram_user'); 97 | 98 | $table->foreign('left_chat_member') 99 | ->references('id') 100 | ->on('theone74_telegram_user'); 101 | }); 102 | } 103 | } 104 | --------------------------------------------------------------------------------