Rooms vs Namespaces for a Chat Widget with Admin Dashboard - node.js

I'm building a chat widget using Facebook Messenger (similar to Intercom live chat or Tawkto or Drift). However, since it's powered by Facebook Messenger user send messages from their Facebook id. The Facebook id of a user will be like pageID_userID (since facebook gives a page scoped user id)
The admin will have a dashboard where he can manage multiple pages and its messages. How can I implement rooms/namespaces in this scenario?
My thoughts: End-user(pageID_userID) subscribes to a room named 'pageID_userID'. When he sends a message, it will be also sent to a room named 'pageID'. And admin opening the dashboard joins to N rooms. Where N is the number of pages he manages.

Related

DialogFlow Manual Handover to Facebook Messenger

I've successfully setup a DialogFlow bot which integrates with Facebook Messenger.
Is it possible for a human user to log into the Facebook Messenger inbox and take manual control over the conversation?
When I log into the Facebook Messenger inbox I've been unable to stop the bot from replying to the user and as a result it ends up being a 3 way conversation between me, the user and the bot.
This usecases makes sense but is not well documented. Facebook mentions this in the handover protocol documentation:
Taking Thread Control From Facebook Page Inbox
For Messenger experiences that enable live chat via Facebook Page Inbox, the handover protocol allows the Page admin to manually initiate a take thread control event by moving the conversation from 'Done' to the 'Inbox'. It is important to note that the thread would immediately be passed to Facebook Page Inbox irrespective of the current app’s role.
I guess this is what you need.
What you need to do is this:
Find the conversation you want to manual control
Check 'Move to Done'
FInd the conversation again by adding the 'done'-filter
Click the Move to Main button (the envelop in the top right
corner)
Remove the 'done' filter to find the conversation
from now on, the inbox has control and your chatbot will not respond if the user types a message. You will be the only one responding
If you need the chatbot to manage the conversation again, just click on the Move to Done-checkmark and the chatbot has control again.
Ps: the documentation also suggests you to subscribe to two webhooks (Standby and messaging-handovers). To be honest: for me it worked with and without subscribing to these webhooks

Is there a way to push notification via a chatbot deployed in facebook developed with dialogflow w/ node.js for fulfillment

I'm developing a facebook/workplace chatbot using dialogflow with node.js for fulfillment. Can't seem to find resources for pushing notifications.
I want to be able to trigger sending the message by visiting the webhook url.
You need to use the Facebook Graph APIs to send a facebook notification to a specific user. User can click on the notification to launch the facebook messenger chatbot.
Here is a quick example.
https://graph.facebook.com/v3.0/{user_id}/notifications?template={your_message}&href={link}&access_token={page_access_token}
You can read more about it here: https://developers.facebook.com/docs/graph-api/reference/user/notifications/
Basically, you need to run a web service which when called makes the calls to the facebook notification APIs.
All you need to do is pass the user id, the message/link to be displayed in the notification and the page access token.
When someone first sends you a message via Facebook, Facebook provides you the page-specific user id which you can store in the database.
Page access token can be accessed by going to https://developers.facebook.com/apps

Can a User resume the chat on different channels(Facebook messenger or Skype) ? where the session should not be lost

I want to make one bot by joining multiple channels like Facebook messenger , Alexa,Native app , Web chat to have a seamless and friction less experience.
User should be able to open and initiate a chat session in-app and close it but not lose the session So that I can easily instigate a chat session with a bot or agent from within the app.
For an instance If I am a user chatting on Facebook messenger bot and after sometime i close it and open the chat bot on the webpage So I should be able to resume the same chat on that channel means session of the user's chat should not be lost.
First of all, bot application connects to mulitiple channels and each channel has its distinct users from others. So as #christophe-willemsen said, you need to build up your own account system and link to all the channels your bot connect. With which, you need to pair the session data with the user.
Then, you can leverage Manage state data to store and access user data. And leverage Advance the waterfall to manage the waterfall steps inside the dialogs.
For quick reference:
let savedSession;
var bot = new builder.UniversalBot(connector, [(session) => {
if (savedSession) {
var [savedDialog] = savedSession.dialogStack().slice(-2, -1);
console.log(savedDialog);
session.replaceDialog(savedDialog.id, savedDialog.state)
} else {
savedSession = session;
session.beginDialog('form');
}
}]);
bot.dialog('form', [...waterfall steps...])

Can I start the conversation with messenger bot?

My bot is running in perfect conditions when I use it trought funpage.
But what I want to know is if we can start the conversation with the user instead user with it.
For example: The user is on a page that his next interation is talk with my BOT. But i don´t want my clients start I want my bot starts.
At this case we can consider that user already authorized my app.
Not if this is their first messenger interaction with you.
When you message a user, you're sending a message to a user id that is page scoped.
So unless they've previously messaged your page, there's no way for you to get their id
The id must be an ID that was retrieved through the Messenger entry points or through the Messenger webhooks (e.g., a person may discover your business in Messenger and start a conversation from there.
These IDs are page-scoped IDs (PSID). This means that the IDs are unique for a given page.
If you have an existing Facebook Login integration, user IDs are app-scoped and will not work with the Messenger platform.
(see https://developers.facebook.com/docs/messenger-platform/send-api-reference)

What draw the borderline of abusive use of Facebook Chat API

The facebook chat api is a power tool. From a purely technically point of view, it definitely does more than its predecessor of private messages in the Graph API.
This brings up a question of where Facebook is drawing the line of abuse of its chat api.
So here's how I'm planning to use the Facebook chat api for my app.
The app is an event planning app that lets users invite their friends to an event. Other than sending SMS, and emails to notify the guests, the most reliable way is to send invitations through the list of facebook friends. And let's face it, sometimes you may not have the person's phone number in your contact book, and you definitely don't remember most of their emails, so facebook is your only source for reaching them.
So I need a solution to send invitations to the guests. Here are my requirements and conditions:
The guest is a facebook friend of the user
There's no way of obtaining the guest's email (unless the user enters it) or phone number (ie. sms is not an option)
Each guest must receive a link that is unique to him/her
No one else should be able to obtain this link (ie. the message shouldn't be seen publicly)
It must not require the user's interaction to send these invitations (imagine having the user confirm a facebook post 10 times for the 10 facebook friends he's inviting). The invitation must be sent automatically.
Here's the obstacle. Facebook had revoked the functionality to send private message recently (I was able to have my facebook friends send me private messages via an app just over a month ago, not anymore). However, I discover that I could do so using Facebook Chat API.
This seems to be a grey area, my app is using the chat api for the sole purpose of helping the users notify their friends of their event invitation. There's no intention of abuse (such as mass messaging everyone of the user's friends with a link to my APP/website). Is Facebook going to hunt me down and revoke my App's privilege to use Facebook's API?
Can anyone shed some light on whether my intended usage of the API is an abuse or is it legitimate? If it is not legitimate, what are your suggestions.
I'd recommend using core functionality wherever possible here. For example, you could utilise the Facebook 'Event' object and the Graph API to create invite-only events and to invite individual friends of your app's users. This would deliver the same functionality without the need for nonce-based invite URLs and possible misuse of the Chat API. Take a look at https://developers.facebook.com/docs/reference/api/event/#invited for details.

Resources