Date picker card for Facebook Messenger bot - facebook

I know that there are various CTA cards that Facebook bot can use as seen here.
What I really need is a datepicker card that can be sent to the user where they can choose a date and send it back. Is this possible using Facebook bots?

Facebook messenger has not launched date and time picker in its templates.
But you can make you own with webview and Extensions help.
Follow these steps.
Create Button or Generic Template and put a button with
"buttons":[
{
"type":"web_url",
"url":"http://my_url_which_open_date_picker",
"title":"Select date",
"messenger_extensions": true,
"webview_height_ratio": "compact"
}
]
replace a url with your url.
NOTE: url should be in whitelist Your Domain
Now in that web page you can get userId of that particular user and couls easily map his actions for date picking.
On your page
<script>
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.com/en_US/messenger.Extensions.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'Messenger'));
</script>
When the Messenger Extensions JS SDK is done loading, it will call window.extAsyncInit and you will get userId in that function.
<script>
window.extAsyncInit = function() {
// the Messenger Extensions JS SDK is done loading
MessengerExtensions.getUserID(function success(uids) {
var psid = uids.psid;
}, function error(err) {
});
};
</script>
uids is Object containing user ids
psid Page-scoped user ID
You may also want to close your calander page when user picks date.
This can be done via:
<script>
MessengerExtensions.requestCloseBrowser(function success() {
}, function error(err) {
});
</script>

Related

Facebook Messenger Checkbox Plugin not displaying - Where am I going wrong?

I am trying to get this Facebook Messenger Checkbox plugin working within a landing page, but it really won't behave and I can't crack why.
It's worth noting I am using Mobile Monkey for their chatbot feature. They provided a simple script which I embedded in the head and a div that you just place where you want the checkbox to display.
Of course, it's not showing, but I'm guessing it won't work without Facebook's integration?
I have including the Facebook SDK, Messenger SDK, etc. I even got the messenger checkbox to display for a short while, but now it's decided it would rather not show itself anymore. Here's everything I have included. If I am going wrong anywhere please let me know, I don't honestly know what I'm doing with all Facebook's developer features.
window.fbAsyncInit = function() {
FB.init({
appId : '(App ID is here)',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.2'
});
FB.Event.subscribe('messenger_checkbox', function(e) {
console.log("messenger_checkbox event");
console.log(e);
if (e.event == 'rendered') {
console.log("Plugin was rendered");
} else if (e.event == 'checkbox') {
var checkboxState = e.state;
console.log("Checkbox state: " + checkboxState);
} else if (e.event == 'not_you') {
console.log("User clicked 'not you'");
} else if (e.event == 'hidden') {
console.log("Plugin was hidden");
}
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function confirmOptIn() {
FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, {
'app_id': '(App ID is here)',
'page_id': '(Page ID is here)',
'ref': '(Ref is here)',
'user_ref': '(User Ref is here)'
});
}
</script>
Is there anything missing here? From following all of Facebook's documentation this is all I should need to get the plugin working, but I may this wrong.
Regarding mobile monkey's little html element not working, their support is terrible and really don't seem willing to offer any help into this situation.
Did you check the browser version of chrome? I think the fb plugin is not loaded with the chrome version 74.

facebook messenger - close webview and notify webhook

I'm sending the user from the messenger chat to a payment page in my application.
Messenger opens the page in a webview.
Now I'd like to close the webview and send the user back to Messenger while also sending something to the webhook in order to notify it that the user has finished the payment page.
What is the best way to accomplish this?
You can only achieve this if the payment page is controlled(developed by you), if it is a third party payment gateway there is nothing you can do. if the payment page is controlled by you, you can pass the sender ID as a parameter via web_url or get the sender ID via
<script>
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.com/en_US/messenger.Extensions.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "Messenger"));
window.extAsyncInit = function () {
// the Messenger Extensions JS SDK is done loading
MessengerExtensions.getUserID(function success(uids) {
var psid = uids.psid;//This is your page scoped sender_id
alert(psid);
}, function error(err) {
alert("Messenger Extension Error: " + err);
});
};
</script>
using the sender ID you can then send a message text back to the bot.
to close the webview after all of this include this script after sending the
text to the bot
<script>
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.com/en_US/messenger.Extensions.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "Messenger"));
window.extAsyncInit = function () {
// the Messenger Extensions JS SDK is done loading
//close the webview
MessengerExtensions.requestCloseBrowser(function success() {
}, function error(err) {
});
};
</script>
Just like from within your Bot you have to ensure that the page access token is available before you send the text, also ensure that you whitelist the domain used in you webview and you set "messenger_extensions": true, in your web_url button or you won't be able to get the Sender ID using messenger Extension
references
url button
messenger extension

Notifications with Facebook Comment Box

I've been reading through other related questions here, but I think they are even too advanced for where I am at with Facebook's coding and such...
I want to have a Facebook Comment box on my website. That is no problem and it works fine. I also want to be notified, on Facebook, when someone leaves a comment. I've tried numerous different things with the comment.create but I really don't have a clue what I am doing.
Can someone take me through this step-by-step and help me understand what I need to do? Here is what I've got:
<body>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=362160727158879";
fjs.parentNode.insertBefore(js, fjs);
}
</script>
<div class="fb-comments" data-href="{site name}" data-num-posts="10" data-width="650" notify="true"></div>
WX, I have a Classifieds app on Facebook. I needed to create some notification to the owner of the advertisement also. I solved that with a simple way, after a comment I manipulate the response from FB with Ajax and Jquery:
FB.Event.subscribe('comment.create', function(response) {
//Send an email with ajax
$.ajax({
type: "POST",
url: "sendcommentemail.php?",
data: "urlofpage=",
beforeSend: function() {
$('#loading').show();
},
success: function(html){
$('#loading').hide();
},
error: function(html){
}
});
});
good luck!
What you need is just add a friend in the app settings on the page as moderator.
He/she will get notification in their Facebook profile each time someone is commenting on your website.
Also, this tool is very handy and to be Favorited for people with developer accounts:
https://developers.facebook.com/tools/comments

display hidden content once facebook like button clicked

On external website (not fb page) would like to put like button where once visitor click like button , it shows certain content.
Here is the code i might thinking it works if i'm not wrong but needs more help !
<div id="fb-root"></div>
<fb:like send="false" layout="button_count" width="100" show_faces="false"></fb:like>
<div id="hidden_content" style="display:none;">Thank You Dear</div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '185373538XXXXXX', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
FB.Event.subscribe('edge.create', function() {
$('#hidden_content').show();
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
So any idea !
~Thanks a lot
Here's my idea (since you're looking for ideas and references).
edge.create will only fire when a user likes the link. You will need to account for what happens when a user comes to your page that previously liked it. I would suggest looking for a way to determine if the like has showed up.
Here's some documentation to read thru:
This might get you the graph id of your web page's url via the object_url table
SELECT url, id, type, site FROM object_url WHERE url = "http://developers.facebook.com/"
Then see if you can track it down in either a stream posting or in a like

Why is the facebook "like" button showing "Be the first of your friends to like this"

I am linking to a page that has 100 likes already. I just started testing it and its now showing:
Be the first of your friends to like this
instead of:
100 people like this
does anyone know why facebook would show that message above versus showing the number of likes the page have? Is that configurable or a bug ?
I believe that shows when a user who has not liked the page and has no friends who have liked it is logged in. According to this question (How to remove the "Be the first of your friends to like this" part of the standard iframe Facebook Like button?), this is not configurable.
please check your URL and put this in body tag
<!--FB SDK-->
<div id="fb-root"></div>
<script>
(function (d, s, id)
{
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!--FB SDK-->