Is is possible to create a custom messenger bot on Facebook? - 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/

Related

Hangouts Chat bot to post timed message

I can see from this, that a bot can send a message in chat, and if supplied a thread ID that does not exist, will start a new thread and post there. I am wondering if there is a way, given the current REST API or any other compatible with Hangouts, to send a message to a room at a given time of day, rather than when the bot is called or interacted with.
I am working in NodeJS, deploying my project in the GCP.
My apologies for the ambiguity of my question, I am trying to wrap my mind around the GCP environment.
In the bots documentation there are described the three ways in which a bot can send a message to a room. Those are:
Every time the bot is mentioned.
When the bot enters a room for the first time.
When the bot is taken out of the room.
Unfortunately, none of them is a daily message at a given time. If you still have questions, please ask them freely.
We have a working bot (NodeJS based) which sends messages freely. Just use this endpoint https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create .
Your bot must be invited to the particular space/room for this. You can create threads as well with new and subsequent messages.
We also have bots written in Google Apps Script and there it is also possible.

How do you make Facebook Messenger bot broadcast message?

I'm facing the problems while making Messenger bot broadcast message. I can make it broadcast at first, but I find that when the bot have to send message to a big amount of users (around 100-200 users). It proceed very slow and some users don't get the message.
I'd like to ask you guys that:
How do you write code to make bot do broadcast? For me, I just put sendTextMessage it the loop which run all page-scoped ID of users. As far as I know, Facebook don't provide specific broadcast or batch sending command right?
According to documentation, Send API do have its limit, but no number specified. It say that 'Messenger Platform supports a high rate of calls to the Send API'. I'd like to know how high is 'high rate' ?
Facebook just updated its Messenger Platform yesterday (7 Nov).
It's now support Broadcast API (beta) and custom label for targeting recipient. Looks interesting.
https://messenger.fb.com/blog/2-2-release/

Facebook Messenger Send Api - send to a big amount of users

I have a bot over Facebook which people are subscribing for sports updates.
I have 1,000 - 10,000 users I want to send out an update to.
Currently, in small scales like 20 messages , I would use a Facebook Batch request.
But, i'm not sure what would be the best way to send my messages in a large scale.
My two options are:
Batch - limited to 50 requests per batch request.
I don't really know if I should expect a delay in the execution of the request.
Regular calls - I will iterate through my receivers and send each of them a message separately.
I'm afraid Facebook might block me for thinking i'm spamming, or I will exceed the rate limits.
I have to say I was expecting a more generic method coming from Facebook since they are allowing users to subscribe for update through my bot, hence, I was expecting them to provide a guide on what are the best practices for sending the update users subscribed for.
You should definitely use Facebook Messenger Broadcast API for this. This will broadcast your message to all user subscribed to the bot.
Caveats:
You have to apply for this permission. (pages_messaging and pages_messaging_subscriptions.Takes about 1-2 days, but
can test on Admin/Test users of the app)
Each broadcast has to be a separate broadcast. (e.g. you can't send image and a text together, each has to be its own individual broadcast).
Have some kind of un-subscription option as well. FB user might think you are spamming even if you clearly say in the messages that your bot will send updates.
Use custom labels to create targetted sends. So you can either subdivide who you will send updates to about specific issues or just label people if they unsubscribe to your broadcast or not.
Basic workflow:
Get permission to broadcast.
Create message_creative_id via POST to endpoint
Use message_creative_id to POST a broadcast_messages
On a successful send you will get back broadcast_id

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

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?

Monitoring new likes and automatically sending a private message

I would need to write a script in order to automate this task:
Monitor new likes on a Facebook Page periodically.
When a new like is detected, identify the person who gave it
Send them a private message, thanking them and pointing them to additional resources that may be of their interest.
Would this be feasible using the Facebook API? The documentation strikes me as a little unwelcoming for the casual observer, and I'm not sure whether this is impossible or it's just that I haven't dived deep enough. Are the three steps above doable using the API?
You can use a cron job to get the number of likes of a Page with the /page-id endpoint.
You can´t get the fans of a Page with the API, and you can´t get the "last liker" either.
Auto-sending and message prefilling is not allowed (it would be spam anyway), and you can only reply to use messages as a Page. You can´t initiate a conversation.