Rendering Facebook Messenger "Send to Messenger" Plugins When Previously Authenticated - facebook

The application I am working on relies heavily on notifying users. I want to leverage the power of messenger by giving the user the ability to subscribe to notifications sent right to their Facebook Messenger. This only became an option for me when Facebook opened up the Facebook Messenger Platform, but I think it is a great way to use Facebook's fantastic product to my advantage and give the luxury to my users.
I have strong understanding of how the platform works and have created my own webhook receiver for the callbacks that are fired when the user selects the "Send to Messenger" plugin. I have also added the Facebook Javascript SDK and rendered the plugin on my page.
I have a few questions regarding the functionality:
Once the user goes through the flow that results in pressing the "Send To Messenger" button I am able to retrieve their sender_id from the webhook callback that is fired and make calls to the Send API using it to send them a message, when the user goes through the flow the plugin has a checkmark. But when I reload the page the plugin gets reset to the default state and does not have the checkmark, how can I render the plugin to have checked state? Because I know the users sender_id now, I don't need them to go through the flow again and fire the same callback. I have the ability to check if the user has gone through the flow, but how can I render the plugin in the correct state, looking for something like this:
if (user.sender_id?) {
# show the check marked "Send To Messenger" plugin state
}
else {
# show the default "Send To Messenger" plugin state
<div class="fb-send-to-messenger"
messenger_app_id="APP_ID"
page_id="PAGE_ID"
data-ref="PASS_THROUGH_PARAM"
color="blue"
size="standard">
</div>
}
Can I store a users sender_id in my database once they have gone through the entry point once? Does the sender_id ever change?
Any insight is greatly appreciated, thanks!

The way I solved this was to set my User ID from my database as the 'ref' or 'pass through params' for the Messenger OptIn. Then in my webhook, when I received the request, I added the Sender ID to the database collection for my User.
When the user reloaded the page, if the user had an associated Sender ID, I didn't render the messenger plug in at all. The Sender ID doesn't change.

Related

How to send any actions to my API by facebook-messenger API if the person isn't available?

When a user blocks my facebook bot account I can't handle any query about this action, but I need this information on my API. I try to write to an unavailable person from Facebook Page, but I just get an error "this person isn't available right now" in front and without query to my API
How I can handle, find and check unavailables users?
I thought to handle actions from chat on application's Facebook page (Mark as Done, Delete chat, etc), but I don't know how I can to get this on my API.
Facebook actions
There is no specific event for such an action (user blocking the conversation), so your only option is to handle the person-not-avail error response and mark those users on your end.

How can I show a dynamic welcome message using Amazon lex bot?

I am developing a chatbot using Amazon lex. It is going to be integrated with facebook messenger in a facebook page. When a user opens the bot for the first time, it says nothing. It listens to user intents. I would like the bot to initiate a conversation and provide the user with a few options(configured in a mysql database in the backend). What is the best way to do this?
There is a get_started event which you can subscribe to with FB Messenger
See the Docs
When triggered, hit your db to get whatever response is appropriate based on the context you have from the event, and anything in your DB.

Is there an event or other way to handle the user first ever message to the bot on the Facebook Messenger Platform?

I have set up a welcome message to my chat bot on Facebook Messenger platform. Now I want to know when the user sends it's first ever message and handle this special case (typically by getting some more info about the user and storing it for future use and not query facebook graph API on every message).
Is there a special event when the user clicks the "Get started" CTA on messenger ? Any other easy way (except storing some data identifying the user myself) ?
This seems to be solved now with the latest additions from facebook:
https://developers.facebook.com/docs/messenger-platform/thread-settings/get-started-button
So you can just enter the specific payload for the "Get Started button" and act accordingly.

Workflow for a message/item sending Facebook canvas app using new Request 2.0

Working on my second app and the first using the new Request 2.0 and other recent features.
I've managed to get the app to log a user in and grant the extended permissions.
My app is simple: I want a user to be able to send a message to a friend along with a user-selected graphic to go along with the message. I guess the basic metaphor is a gifting app.
I'm not wrapping my head around the workflow especially as examples using the new Request 2 dialog seem few and far between.
Here's what I'm thinking the beginning of the workflow looks like:
User arrives at app page. Logged in, permissions granted if needed
User selects a graphic (via an html radio button form) to go along with message they enter into an html text form
User selects friend(s) to send the message/graphic to.
I'm assuming I should toss the senderid, receiverid(s), link to graphic (or id), and message into a database.
How do I get the info from my users' selections? Does hitting Send Requests on the FB dialog POST the FB and form POST info to the same page so I can read them via PHP $_POST variables?
When the person receives the request, they accept it, but how do I get them to go through the requests outstanding and display the graphic and message? i.e. Archie logs in and has 6 friends sending him items through my app. How does he, in FB methods, see the message/items that Veronica, Betty and Jughead have sent him?
I don't mean that in a basic way. I know how to do this all if I was just writing a PHP app on my own site. I'd be finished in a few minutes. The part that's causing a head-shaped dent in my desk is trying to work out how it works adding Facebook to the workflow. I've been looking for examples and tutorials but they seem to be out-of-date to the new methods FB wants us to use.
Thanks for any pointers!
When a user follows a request you have access to that request ID. If you need to access additional requests the user needs to "Connect" with your app so you can read that info from the user object. The request ID for the acted upon request will be available to you on your canvas page and it will be up to you to develop a work flow that authenticates the user to be able to access any other requests for that user.
The related blog post that discusses the process is available here:
https://developers.facebook.com/blog/post/464

Facebook API: create event using Facebook's form

I've done my searching for the answer to this but it remains unclear. This could be a simple "possible" or "not possible" answer.
I have a site I'm creating that uses Facebook Connect (may or may not be relevant). I would like users to be able to create Facebook events based on events posted on this site. I'm familiar with the Facebook API and realize I could make my own form that would allows users to create a Facebook event... but I don't really think I want to do that work.
Is there a way I can point a user to Facebook's "create event" form but simply pre-populate some of the fields to help them along?
For example, say I wrote post about a free concert and had a button that said "make this an event on Facebook!". I would like that to link back to the fB event form with a title "Reggae Night 2010" and then from there the user could go on and create the event as they normally would. I don't see the point in doing my own form, validation, etc.
Thanks!
Firstly, obviously have a FB login enabled page and/or when the click your site's "click here to create event in Facebook" button, then have it check for whether the user is already logged into FB. Then use javascript to prepopulate the fields on the form on this page...
http://www.facebook.com/events/create.php
...with the info from your site's event.
That should be it!
-Flak
EDIT: spankmaster79 - yes, that's what I said above.... have your code CHECK for WHETHER you're ALREADY LOGGED INTO FB first. (Please remove the -1, I'd appreciate it)