-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Twitter Driver: Simple echo chatbot going into infinite loop #2
Comments
I haven't used the Twitter driver yet. Is still not working or did you found a solution? |
Thank you for replying. The original code is still not working. I found a solution that works for my situation. Taking the current TwitterDriver as base i wrote a custom driver - overriding the problematic functions that i needed. I was not able to resolve all the problems of the driver. |
Hi, This can be fixed by checking user id of sender <?php
$botman->hears('(.*)', function (BotMan $bot, $text) {
// Get user
$user = $bot->getUser();
// Get user id
$user_id = $user->getId();
// Check if twitter user id is not bot id
if($user_id != $twitter['user_id']){
$bot->reply("Echo: ".$text);
}
}); Maybe we can add new parameter to config "user_id", so when twitter send back message we can detect it from "recipient_id" and then pass message as false? What do you think @mpociot ? Thanks. |
I had to make changes to two functions in TwitterDriver.php for it to work. It works for my requirement, don't know whether it will work for all the requirements.
|
@dimplevador well, changes made by yourself in the source code isn't good choice. When library will be updated you'll need to follow up changes. Does my example works as expected for you? I still think that we don't have to make up any changes because it's really useful feature for some kind of logging (messages can be sent from any app integrated with twitter, so checking source app is also neat !) |
@sololance :) Thank you for taking time to checkout the problem. I didn't make any change to the source code. I just wrote a custom driver by extending TwitterDriver and overrode the two functions - according to my requirements. If i am using the code without any changes, it goes into infinite loop with just one simple echo call. |
Can someone please help me, to send get started information for botman-twitter driver. |
@salmanyaqoobin The existing source code is faulty. You will have to create a custom driver by extending the existing TwitterDriver and override two methods: matchesRequest() and getUser(IncomingMessage $matchingMessage). You can find the new code for both these methods in the above discussion. Documentation for extending / customizing driver https://botman.io/2.0/drivers Please note that this modification works for my purpose. I am not sure whether it will work for you or not. |
@dimplevador Thanks for the Quick Reply, your two functions even solve the loop messaging issue.
Welcome Message with image Code (browser base controller approach)
|
@salmanyaqoobin I am glad it worked out for you :) Thank you for sharing the welcome message with image extension function. |
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 :
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:
The text was updated successfully, but these errors were encountered: