botman / botman/driver-twitter

Twitter Driver: Simple echo chatbot going into infinite loop

Open
#2 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
7
Forks
6
PR merge metrics
No merged PRs in 30d

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:
```
[
'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();
}
?>
```

Contributor guide

Open the contributing guide

Research direction

Start in src/TwitterDriver.php at getMessages() around line 68, using the webhook payload and echo-bot example in the issue as the entry point. Compare how incoming direct messages and delivery reports are handled. Done means the bot replies to a user message without treating its own delivery report as another message.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.