0

I have created a Facebook messenger bot that is working perfectly. I used php to create it.

Now, I want to add some new functionality. When the bot owner is online in Messenger and starts answering messages, the bot should stop responding to users.

How can i detect when the owner has started answering?

Yeezy
  • 13
  • 3

2 Answers2

1

A simple idea is to send the Bot a message from an administrator account. For example, if the admin sends 'STOP' then the Bot stops sending messages until an admin sends 'START'.

The incoming events to the Bot contains the sender id. The sender id would have to be correlated to a particular administrator id. The only way I have found to get that id for a particular user is to send a message and print out the id. The id is specific for the Bot and user combination. For example, my Bot will send a message to my personal account with this JS line:

 sendTextMessage(1073962542672604,fistName + " " + lastName + " " + messageText); // send a message to Matthew directly

Sounds like you have a bot working but if you need more details, have a look at my Bot and source code.

Just for fun, I added this functionality to my Bot. To see details in the node.js implementation, search for the 'isStopped' variable in the app.js script.

Matthew Fisher
  • 2,258
  • 2
  • 14
  • 23
1

I did a test on this before.

You can try subscribing to "message_echo" webhook. This webhook is called when the page AND the bot sends a message to a user. So you'll need to differentiate which "message_echo" is from the page (a person) and which is from the bot. In the json that webhook sent, messages from the bot will contain an app_id key in the message object.

Your server will get a lot of hits by subscribing to this webhook.

user3377465
  • 128
  • 6