shopium/mod-telegram

Telegram机器人

此包的规范仓库似乎已消失,因此包已被冻结。

安装: 130

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

语言:JavaScript

类型:yii2-extension

1.0.0 2020-12-21 12:57 UTC

README

Latest Stable Version Total Downloads License Daily Downloads Monthly Downloads

基于Telegram机器人的站点支持聊天

该机器人的逻辑基于 akalongman/php-telegram-bot,因此您可以阅读longman的说明来注册Telegram机器人等。

目前只支持telegram webhook api。您需要SSL证书!http不工作!

安装

安装此扩展的首选方式是通过 composer

运行

composer require shopium/mod-telegram

添加到您的配置

 'modules' => [
     //...
    'telegram' => [
        'class' => 'shopium\mod\telegram\Module',
        'PASSPHRASE' => 'passphrase for login',
        // 'db' => 'db2', //db file name from config dir
        // 'userCommandsPath' => '@app/modules/telegram/UserCommands',
        // 'timeBeforeResetChatHandler' => 60
    ]
    //more...
 ]

运行迁移

php yii migrate --migrationPath=@vendor/shopium/mod-telegram/migrations #that add 4 tables in your DB

或添加到您的配置文件

'controllerMap' => [
    ...
    'migrate' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationNamespaces' => [
            'shopium\mod\telegram\migrations',
        ],
    ],
    ...
],

并运行

php yii migrate/up

访问 https://yourhost.com/telegram/default/set-webhook(如果不是prettyUrl https://yourhost.com/index.php?r=telegram/default/set-webhook

现在您可以将它放在您想放置的地方

echo \shopium\mod\telegram\TelegramWidget::widget(); //that add chat button in the page

如果您想限制消息历史记录的存储期限,请将其添加到您的crontab中

#leave 5 days (if empty - default = 7)
php yii telegram/messages/clean 5

您还可以使用自定义命令。为此,您可以从 /vendor/panix/mod-telegram/defaults 复制 UserCommands 目录,并在配置中添加此路径,例如

'userCommandsPath' => '@app/modules/telegram/UserCommands'

timeBeforeResetChatHandler - 在聊天处理程序被杀死(如果它忘记了执行/leavedialog)之前的时间(分钟数)。如果为0或未设置,则永远不会杀死。