Facebook Messenger Bot - How to disable bot and allow human to chat - facebook

so this is something I've been trying to think through for about 16 hours. I am coding with PHP / CuRl / etc - the bot works and everything is fine. My current issue is figuring out how to disable the bot and allow a human to begin chatting with the customer/sender.
Has anyone successfully, created a route for this ? I mean it's pretty hard from what I see, you'd have to disable etc etc. A lot of effort for my clients.
Thanks for any input.

Facebook has rolled out a "Handover Protocol" which is supposed to facilitate a combined human/bot Messenger implementation.
https://developers.facebook.com/docs/messenger-platform/handover-protocol
It is a little unclear what actually occurs in step 5:
Pass thread control: At some point in the conversation, a user may choose to do something like interact with a live agent. To handle this, pass thread control from the Primary Receiver to the Secondary Receiver. The Secondary Receiver will receive a messaging_handovers webhook event to notify it that is now controls the conversation.
This doesn't actually disable the bot (as the OP requested), and isn't in the control of the Page owner but rather of the user. It seems FB envisions the user typing something like 'I would like to chat with a human' triggering the bot to pass control...but it would be nice to let the page owner simply put the app in standby and handle the messages herself.

Once you recognize someone wants to speak to a human, set a flag that disables all actions of your bot to on.
Then, have your bot message you, or whoever will respond, that a user ID needs responding to. Have your bot continue to send all messages received from them back to you until you enable the bot again.
Create some sort of way for your bot to interact with you that allows you to send a message to a specific user, and a way to once again enable the bot interaction with the user.
Probably something like "sendMessage104012301230'Hi, sorry you couldn't find [etc]', and enableUser104012301230
There may be a better way, but those are some thoughts on how I'd do it

If you enable messages echo, whenever a human respond using the page, a echo post is sent, and inside entry->messaging->message there's no app_id.
You can use that information to disable bot replies for a certain period, or disable indefinitely until you enabled is with some admin command (that's how I'm doing)

I thought a solution could be to label the message as "unsolved". Another solution could be to have the bot mark the conversation as unread. Does anyone know if it is possibile to add a label to a conversation or mark as unread through API?

Related

Is is possible to create a custom messenger bot on Facebook?

I would like to know that we are having a lead generation campaign running on Facebook but few of the times our staff isn't available to answer the query on Facebook messenger, so based on that short-coming I am thinking to devise a mechanism that "If within 1 hour of user's message no one replies to him then an automated BOT message should get sent to him."
Please don't deprecate this question as it is based entirely on knowledge. And if perhaps someone has hints or links on how to achieve this thing then I will really appreciate it.
Thanks.
Some options:
You can query your /conversations edge every X minutes to detect when there is a message from a user which has not been replied to, then you would send the automated message using Send API.
https://developers.facebook.com/docs/graph-api/reference/v10.0/conversation
https://developers.facebook.com/docs/messenger-platform/reference/send-api/
You can use webhook data for incoming messages to create a task that will run at received_time + 60 minutes, find the thread in your conversations edge based on PSID and then check if there has been a reply
Alternatively you can check out Handover Protocol which allows a Page to simultaneously use a Messenger Bot and Live chat agent to handle messaging
https://developers.facebook.com/docs/messenger-platform/handover-protocol/

How can the recipient be informed that someone has blocked them on ejabberd?

We are building a chat app using latest ejabberd and there is a use case where user A blocks user B. the requirement is to hide last seen or user's presence from each other. if A blocks B then its easy to hide these information from user A but how can user B be informed that user A has blocked them ? whats the best approach to tell user B the someone has blocked them on realtime while both are in a conversation , like whatsapp does now.
For presence, you do not have to use block, you can simply remove contacts from roster. That way, the other user is notified and can also stop sharing his presence.
There is XEP-0191: Simple Communications Blocking:
https://xmpp.org/extensions/xep-0191.html
https://xmpp.org/extensions/attic/xep-0191-0.2.html
I think it will give you the answers you need. Now it depends how will you implement this functionality using chosen client library like Smack.

Quick Replies on the Page Owner

Messenger Platform introduced Quick Replies feature, that the User can tap to answer Page Owner's request instead of typing. However, I can make it work from the User view only. Will it work from Page Owner's view, like suggestion?
Flow may be:
1. User ask Page a question
2. Bot suggest some <quick replies> based on that question (maybe use NLP)
3. Page Owner can tap <quick replies> to reply
I may call this "semi-auto reply bot". For example, in the demo here, the shop owner may double checked the response and tap to send.
No, there is not a direct way to do this. Theoretically you could basically have a customer-facing bot and a business-owner-facing bot, and then orchestrate the a flow something like this:
user messages user-facing bot
bot forwards the message to business in business-owner-facing bot with quick replies
business owner selects a quick reply
user-facing bot replies with the text of the quick reply.
You'd want to be careful of privacy concerns tho since the user's message is being forwarded on.

How do I implement a "hand back" from Facebook Inbox once I "hand off" from my chatbot

Building a chatbot and trying to implement the handover protocol. SO far I have it handing off to the inbox, so that if someone asks for customer service, the bot hands over to the inbox and presumably someone who is monitoring the page can answer. Once the inbox is the primary receiver, I can't find a good way to hand it back to the bot ... I know that I can set a timer and have the bot request
for the conversation to be handed back, but this does not seem like the best approach
mark the chat as 'Done' in the Page inbox and thread control will be returned to the primary receiver app.
I was interested in this functionality, but I was also wondering is there any way of monitoring whether a question has been answered after handing over to the inbox? So my chatbot can check and then take back control if it hasnt.

FbChatBot mark message as Read

i am developing fb chat bot, and i want to mark the message as read so that when the moderator of our fb page view the message part, they won't see so many unread messages even though the fb chat bot has already replied that user and they don't need to click that message just to mark it as "read".
How can i achieve this? I am trying to use this API: but it doesn't work.
https://developers.facebook.com/docs/messenger-platform/send-api-reference/sender-actions
You can not mark message as read (as of now), but the best way I deal with this is to use Handover Protocol
When your bot reply the message, it won't appear in INBOX, but it goes to DONE box instead.
When bot cannot answer, you can let your bot pass thread to INBOX. Then the moderator of page manually answer it. (and mark as DONE afterward)
Follow the instruction here to set it up:
https://developers.facebook.com/docs/messenger-platform/handover-protocol/pass-thread-control
(Note: You can pass thread to page inbox and then take thread back immediately. I will notify to INBOX, but your bot can still work with users.)
When you use the API you sent here (Facebook's Send API), you only mark the message as "seen" from the bot on the Messenger Chat that you have with your users. This doesn't affect the messages inside your Page's inbox.
Unfortunately, there is no way to mark messages as read inside your Page's inbox.
Is this new feature of fb bot? Thanks btw! I will try to check this.
Is there any side effects in Marking the message as done ???
To answer your question:
There are some bugs within the Inbox/Pages Manager mobile app. You won't see the messages in DONE folder if your admins are using Pages Manager mobile app for now.
I've reported the issue and working with them to solve it. However, you can still see those messages in DONE folder if you use a computer and go into your page's Inbox.
NOTE: It seems that messages moved to Inbox will be marked as seen (not bolded). This may be a little confusing if your admins don't mark each conversation as DONE after admin finishes conversation with the users.