Facebook Oauth-enticated users, chat between themselves on website - facebook

I have a website where users log in with Facebook. Right now there's no way for users to contact each other.
I was thinking of building a dedicated live messenger with sockets, but I wonder if there's an easier way to allow them to send messages to each other's Facebook Messanger, since they are already logged in with facebook.

There is no API for a chat between two users. Everything in Messenger API is focused on communication between a user and a page.
At most you can use the Send dialog to let a user send a link to their friends, but that requires the user actively using the button, you can not “automate” that; and handling the result will have nothing to do with your site any more, everything after that will happen in messenger only. https://developers.facebook.com/docs/sharing/reference/send-dialog

Related

Can i send direct messages to my clients facebook followers using API?

I have seen services advertising that they can message the followers of pages and accounts on Facebook. I have gone over lots of different Facebook API's and several interesting threads on here but cant find a definitive answer.
Is is possible to directly message via a bot users who like a page providing obviously we have a valid admin token for that page?
Is is possible to directly message via a bot users who like a page
No, that is not possible.
All communication via the Messenger platform API (basis for “bots” in Facebook terminology) requires that the user initiates it.
And it would probably be considered spam by most people - just because I liked your page, does not mean I want to be contacted by you in any way beyond that. Posting to your page is the designated way of communicating with the people that follow your page.

Create multiple Facebook messenger bots with one app

The Facebook messenger bot API seems to require you create a Facebook app for each bot, for each page. The Facebook app stores the webhook, and connects to the page.
Is there a way to have a single Facebook app for many bots connected to many pages?
If you create a bot to resell to clients as a service, you need to be able to do this. But there does not seem to be any way. You need to create a Facebook app for each client, and go through the Facebook app review process for each page which is very difficult.
How can this be avoided?
Can a single Facebook app have multiple webhooks, or access to multiple pages messages?
You can create one chatbot and can use this bot in multiple Facebook pages. All you need is to store PAGE_ACCESS_TOKEN for each page and response messages to the user with right PAGE_ACCESS_TOKEN. You should get the necessary permissions to get page access tokens by Facebook Login. And then you need to subscribe the page to your chatbot(app): https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps
One important thing is Facebook generates a unique identifier for users for each page. Some user#A will have a different SENDER_ID/RECIPIENT_ID on different pages.

Can I give my facebook messenger chat bot the exclusivity of answering users?

I connected a Facebook messenger bot to a page with several admins. I am not yet very familiar with the facebook messenger platform but it looks like when a user messages our page. Admins see the incoming message and can respond to it. Can I deactivate this ? I want my bot and only my bot to handle incoming message, I don't want admins of the page to be able to interfere in the user experience. I was thinking it should be easy to do but I cannot find how to do that. To recap : I would like my chat bot to have the exclusivity of chatting with users from my facebook page, do you know how to do this ?
Thank you very much
Admins see the incoming message and can respond to it. Can I deactivate this ?
No, you can not.
Bots are meant to be able to help with page tasks regarding answering user messages, but not to take over control completely.
Well, according to this Facebook help article, the roles available to your page admins are listed there. Use it as your guide.
After searching, I was unable to find anyway to make the conversation between a Facebook messenger bot and a Facebook user private (in the sense that no page admin, editor or moderator would be able to see the conversation from the page inbox). If you want your bot to have a private conversation with your users for certain sensitive actions, your only option as of now seems to be using a webview.
Using a Webview can complicate a little bit your workflow because Webviews are not supported the same way on all platforms but at least, it will enable you to gather direct inputs from your users that your Facebook page moderators will not be able to see from the admin page.

How to test FB messenger bot with multiple users

Has anybody yet a way to interact with an FB messenger bot without using real FB accounts? I want to do automated testing and obviously not use real accounts for that.
I was not able to figure out how to allow access to a page to 'test users' or create a test page and subscribe the test app to it.
Any ideas on how to do this?
I use a wee web app I made to act as a local version of the facebook messenger api server and run user actions.
https://github.com/Fraser-Greenlee/bot_tester
On it you can write a script to define new users and their actions.
From the Facebook developers dashboard, select your app and then Roles. From Roles you can add other Facebook users as test users. It was easiest for me to use the users facebook id. Adding by email did not always work for me.
I am not aware of how to access a Facebook bot without a Facebook account. I created several fake accounts and had my friends test the bot. After testing, I deleted the fake accounts.
For more information on setting up a bot see my article Facebook Bots for Fun and Profit
The example bot is DMS Software Bot
The source code is Github fb-robot
Testing fb bot with non-fb user is currently not supported. Following are the reasons:
fb messenger requires the user to be logged
fb creates page scope ids (PSID) for each user who is interacting with the bot and hence login on fb is required
Coming to your question on testing:
you can add fb users as tester to your page and your app. Explained here. For your app https://developers.facebook.com/apps/[app-id]/roles/
Once added they will be able to send message to your bot (page) from messenger
On another note, if you are using 3rd party apps to build your bot (eg: api.ai, wit.ai) they already have emulators within the app which makes testing easier.
One easy way to achieve automated testing for messenger bots atleast is to try to mimic a request coming from FB. You can just log the request you are getting to your bot to find the signature of the request that FB sends. Then you can just pretend to be FB by sending http requests with the same signature. You will also have to add in code to respond to these http requests with your reply instead of just sending the message to FB's send API.
So in node it would be something like
sendMessage(<your reply>);
res.send(<your reply>);
Now you have an automated way of sending and receiving messages which you can use for automated testing.
However I think the bigger challenge is coming up with enough test cases. You need to use a combination of clustering over available data and classification to generate new cases.
I have been working on a tool to make this easy. So if you are interested you can sign up for early access. http://ozz.ai

How to invite users' friends via facebook?

I'm looking for a simple way for users to be able to invite their friends to follow them on my website.
E.g Bob invites sally to be a follower of Bob on mysite.com.
I was thinking of doing this via requests, however I've read that they only work for canvas apps and not regular websites, meaning if Sally accepted Bob's request, then my website would be loaded as an Iframe within facebook, this would break the layout of my site and won't look good.
Is there any solution, like showing users a link within the canvas which they can click to have canvas turned off and have them sent to my website?
In the facebook TOS it says that a canvas can't exist just for redirecting users, and yet it says that facebook requests should be used for inviting users to your site.
My question is, then what would be the proper way for a website to let their users invite their friends from facebook?
I think that the only way you can do that with facebook is by sending private messages to the invited users which contains the link to your "invite url".
You can use the Send Dialog with the link parameter being the invitation page for your site.
The problem with this method is that you can not control the message that is being sent, you can however put the needed info into the og tags of that link which are added to the message.
Another approach is to use the Chat API where you have complete control over the messages that are being sent.
Problems with this method is that you'll require an extra permission (xmpp_login) and that you'll need to implement a xmpp client.
This is probably an overkill.