-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
- BotMan Version: 2.0.
- PHP Version: 7.0.3
- Messaging Service(s): Twitter
- Cache Driver: FilesystemCache
Description:
A simple Echo Chatbot for Twitter Direct Messages is going into infinite loop.
I have narrowed down the problem to this:
When user DM's, webhook receives event: "message_create".
When webhook posts reply, twitter sends delivery report (Response) with the following json, notice the event "message_create". The event name is same for receiving actual user message & also for bot message delivery report :
{
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": "RECIPIENT_USER_ID"
},
"message_data": {
"text": "Hello World!",
}
}
}
}
I have not been able to find difference between incoming message & delivery report json. Can someone please help me out with that?
The function that needs to be fixed in Twitter Driver is getMessages() on On line #68 - https://github.com/botman/driver-twitter/blob/master/src/TwitterDriver.php
Thank you very much in advance.
Steps To Reproduce:
Twitter webhook:
<?php
require __DIR__ . '/vendor/autoload.php';
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Cache\DoctrineCache;
use Doctrine\Common\Cache\FilesystemCache;
$config = [
'twitter' => [
'consumer_key' => '****',
'consumer_secret' => '****',
'token'=> '***',
'token_secret'=> '*****',
]
];
if(isset($_GET['crc_token'])) {
$signature = hash_hmac('sha256', $_REQUEST['crc_token'], $config['twitter']['consumer_secret'], true);
$response['response_token'] = 'sha256='.base64_encode($signature);
print json_encode($response);
}
else{
DriverManager::loadDriver(\BotMan\Drivers\Twitter\TwitterDriver::class);
$doctrineCacheDriver = new FilesystemCache(__DIR__);
$botman = BotManFactory::create($config, new DoctrineCache($doctrineCacheDriver));
// Give the bot something to listen for.
$botman->hears('(.*)', function (BotMan $bot, $text) {
$bot->reply("Echo: ".$text);
});
// Start listening
$botman->listen();
}
?>
Metadata
Metadata
Assignees
Labels
No labels