The Bot logic based on akalongman/php-telegram-bot, so you can read Instructions by longman how to register Telegram Bot and etc.
Now only telegram webhook api support. You need SSL cert! Doesn't work on http!
The links of this extension
Github: https://github.com/onmotion/yii2-telegram
Packagist: https://packagist.org/packages/onmotion/yii2-telegram
Requirements ¶
Yii 2.0 or above
Usage ¶
Installation ¶
The preferred way to install this extension is through composer.
Run
composer require onmotion/yii2-telegram
add to your web config:
'modules' => [
//...
'telegram' => [
'class' => 'onmotion\telegram\Module',
'API_KEY' => 'forexample241875489:AdfgdfFuVJdsKa1cycuxra36g4dfgt66',
'BOT_NAME' => 'YourBotName_bot',
'hook_url' => 'https://yourhost.com/telegram/default/hook', // must be https!
'PASSPHRASE' => 'passphrase for login'
]
//more...
]
and to console config:
'bootstrap' => [
//other bootstrap components...
'telegram'],
'modules' => [
//...
'telegram' => [
'class' => 'onmotion\telegram\Module',
'API_KEY' => 'forexample241875489:AdfgdfFuVJdsKa1cycuxra36g4dfgt66',
'BOT_NAME' => 'YourBotName_bot',
]
],
run migrations:
php yii migrate --migrationPath=@vendor/onmotion/yii2-telegram/migrations #that add 4 tables in your DB
go to
https://yourhost.com/telegram/default/set-webhook
Now you can place where you want
echo \onmotion\telegram\Telegram::widget(); //that add chat button in the page
in bottom right corner you can see:
if you click it:
and server side:
If you want to limit the storage period of messages history, add to you crontab:
#leave 5 days (if empty - default = 7)
php yii telegram/messages/clean 5
Hello...
I created bot, installed packages, set configs...
And put widjet on single page.
And what i see... just green button at write bottom...
Any clicks do nothing...
In Network console of browser i see request to "init-chat" and back error request - "Bad Request (#400): Unable to verify your data submission."
I found info that i can fix this error just disabling Csrf... but its not save...
Tell me - what legal configure of this situation?
Thanks
Hello!
Do you have registred csrf token on meta tags?
For example like so:
`
phpecho Html::csrfMetaTags();
`
in your layout.
Yii will append csrf param to ajax req header automatically. https://github.com/yiisoft/yii2/blob/master/framework/assets/yii.js#L273
Hello
Sure i have
`
html<?php $this->beginPage() ?>
<!DOCTYPE html>
<meta charset="<?= Yii::$app->charset ?>"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?= Html::csrfMetaTags() ?> <title><?= Html::encode($this->title) ?></title> <link rel="shortcut icon" href="/img/favicon.png" type="image/png">
<?php $this->head() ?>
`
But anyway, button doesn't work...
Any my clicks do nothing... and in network console, i see error
Do you have registred yii.js in your app?
Can you show your POST data and request headers?
Also please try to reproduse this issue on clean installed app, then try run with your config. If you find a bug and can fix it, please make a pull request.
Thank you!
I think - i need disable csrf at telegram controller... but how?
For example in your config
or you can make controllerMap for module. But. as you said, it's not safety.
so if i need bot, i need disable csrf.
if i need csrf safety - i have no bot?!
No, it's not typical bechaviour. I can't reproduse this bug on clean app. So I asked you for
The right way is fix the issue and use the module safely.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.