I have written an app that talks to Facebook messenger. I kept getting the same message from Facebook over and over.
(It's an Express app)
app.post('/webhook23', (req, res) => {
(This is the quantity that was the same each time I got messaged)
req.body.entry[0].messaging.events[0]
(Here's what I got)
{
"sender":{
"id":"1075583395843601"
},
"recipient":{
"id":"1408746912473828"
},
"timestamp":1472824205937,
"message":{
"mid":"mid.1472824205931:3f118e895201854e72",
"seq":122,
"text":"Yes."
}
}
I eventually broke out of this by writing a little program that accepted whatever Facebook said, and returned a 200 status. I drained the pipe, and then I was able to work.
Am I understanding this correctly though? It'll just keep on trying forever? Further messages just wait until the one in front is successfully processed? Is this a good design?
Regards, Rick
Related
I am making a google action.I have one scenario where calculation requires some time in cloud fulfillment but i don't want to keep user waiting for answer.
I want to respond to user whenever my answer is ready even when conversation with user is ended i want to send my answer in notification or something like that.
I just found this on google actions documents.
https://developers.google.com/actions/assistant/updates
Is this possible in google actions and how?
What you mean here is notifications. You can use it but please pay attention to the warning at the top of the link you provided: "Updates and notifications are currently in Developer Preview. You can build apps using the features described in this article, but you can't currently publish them".
As for the steps to crated a daily notification:
Navigate to your actions.intent.CONFIGURE_UPDATES intent.
Under Responses, go to the Google Assistant tab, click Add Message Content, and select Custom Payload.
In the "Custom Payload" box, add the following code to call the AskToRegisterDailyUpdate helper. Swap INTENT_NAME to the intent that you want to be invoked when the user interacts with your notification.
{
"google": {
"system_intent": {
"intent": "actions.intent.REGISTER_UPDATE",
"data": {"#type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec",
"intent": "INTENT_NAME",
"triggerContext": {
"timeContext": { "frequency": "DAILY" }
}
}
}
}
}
If using a webhook, you can call this API directly via the client library:
appMap.set('setup_update', function(app) {
app.askToRegisterDailyUpdate('INTENT_NAME');
})
})
Add one more intent called "finish_update_setup" and enter actions_intent_REGISTER_UPDATE as its Event.
Set the intent's Action to "finish_update_setup" as well.
In your webhook, open index.js and add the following. Replace Ok, I'll start giving you daily updates and Ok, I won't give you daily updates. with whatever response you want to give the user:
appMap.set('finish_update_setup', function(app)) {
if (app.isUpdateRegistered()) {
app.tell("Ok, I'll start giving you daily updates.");
} else {
app.tell("Ok, I won't give you daily updates.");
}
}
Deploy the webhook to Firebase Functions and enable webhook fulfillment in Dialogflow.
If you want to see how to create a simple notification (not daily one) - please check this doc on push notifications.
If you don't have an immediate reply to send but expect one soon-ish what you do is return a "promise". When you are in a position to reply, "fulfilling" the promise causes your reply to be delivered. I don't know what the actual timeout is but in my case I'm pretty sure at least a few second delay is allowed.
As for the updates or notifications, the API is there but the docs say you can't deploy an Action to production using them. There is a slightly cryptic comment to "contact support" if you need them.
One of these days I might try.
So, I am in the process of writing some Google Actions code against the Actions SDK. I am able to receive the requests and process them fine. I am also able to send responses that do not expect user response fine. However, when I send a response that expects a user to make a choice, the google assistant just keeps asking the question over and over no matter what the user says (except stop of course). Here's my response json. Can anyone help?
I should note that ActionOneIntent, ActionTwoIntent, and ActionThreeIntent are all configured properly in the action.json file, and work properly when invoked via a deep command to my service (ok google, ask my service to open action two).
I just can't get a response to this packet to work:
{
"conversation_token":"{REMOVED}",
"expect_user_response":true,
"expected_inputs":[
{
"input_prompt":{
"initial_prompts":[
{
"ssml":"<speak><p>Hello, would you like choice one, two, or three?</p></speak>"
}
]
},
"possible_intents":[
{
"intent":"AnswerOneIntent"
},
{
"intent":"AnswerTwoIntent"
},
{
"intent":"AnswerThreeIntent"
}
]
}
]
}
In the earliest version of the Actions SDK you could define "inDialogTriggers" as part of your Actions package. However, this was removed some time in December and the idea now is that developers process "assistant.intent.action.TEXT" which is the raw transcription of the user's input.
As such your only "possible intent" in the response should be "assistant.intent.action.TEXT" at this point. See here for reference: https://developers.google.com/actions/reference/conversation#http-response
I was wondering if somebody can help me to solve this problem. I am trying to use FB.AppRequest() in Facebook SDK for Unity to implement an Invite feature . This is the code which I use.
if(FB.IsLoggedIn)
{
FB.AppRequest(
message: "Let's eat and be prosperous!",
title: "Let's eat and be prosperous!",
callback: InviteCallback
);
}
// ...
void InviteCallback(FBResult response)
{
// print response to console
}
The invitation dialog which I get can be seen here (link to Imgur). There is no "Invite" label on those buttons, and unsurprisingly, clicking them does not send any invitation. However, I can see the FBResult data, which is in the following format:
{
"request": "ABCD",
"to":
[
"EFGH",
"IJKL"
]
}
(more or less, since I haven't found a way to print new lines to Firebug console)
Additional information:
The result is the same regardless of the Sandbox setting.
The Unity version is 4.3.0f4
The Facebook SDK for Unity version is 4.3.4
The binary is hosted on an intranet server.
The Invite functionality in the Friend Smash example, hosted on the same server, doesn't work either. However, this is before the latest Friend Smash update (11/11/2013), whose Facebook functionalities I can't get to work yet.
Other Facebook functionalities (e.g. Init, Feed, API) work well.
I can't find any information about this on the internet. There are other questions about the Invite feature not working, but without the Facebook SDK for Unity, so I am not sure how they can be helpful to me.
Thanks a lot!
Just to clarify: the envelope button sends the invite, and it does so immediately when it is clicked.
If your app is in sandbox mode, people won't get notified when the request is sent. Look for the request in https://www.facebook.com/appcenter/requests as the recipient and see if the request shows up there.
If this still doesn't work, can you send me your fbresult data? unity-sdk#fb.com. thanks!
This is the first time I'm trying to develop a facebook app so sorry in advance if my question is too naive.
What I need to do is making a chat-like facebook application where:
the user can write something on the wall
the app should be able to detect this event and send an HTTP request to an external web service of my own which will provide a response (text)
publish that text as a comment
the user should be able to continue the dialog by entering another comment(s) (in which case we go back to step #2)
Basically, this would be very similar to:
https://www.facebook.com/SkyscannerFlightSearch
I think one (ugly) way to do this would be making a script which searches for new wall entries/comments and posts replies in an infinite loop by using the Graph API but it's obviously sub-optimal and expensive.
Is there any way to have facebook call a certain url every time a wall post/comment is entered?
Or maybe something like Twitter's streaming API based on long-polling technique?
Am I in the right direction by assuming such kind of solutions or I'm totally missing the point?
Thanks in advance.
Giampaolo
I am working on something very similar myself.
So far i have the "loop" which can be set to any page, group or app on facebook.
SAMPLE: https://shawnsspace.com/plugins/wallfeed.php My page wall.
SAMPLE: https://shawnsspace.com/plugins/wallfeed.php?pageid=19292868552&ptype=feed&limit=40 Facebook Platform Wall.
With some perms, a form and user access_tokens i can make the wall postable. Asper UGLY - you do not need to run this in a loop, Facebook supports realtime updates and will send a response to your app when a user, or page has made a change.
MORE: http://developers.facebook.com/docs/api/realtime
Thanks for the input.
I tried to use the real-time API by using object=user and fields=feed.
If I understood the doc correctly this should result in my callback url being called (POST) every time a user writes something on my app's wall.
I received the initial GET request but never POST.
This is the current configuration:
{
"data": [
{
"object": "user",
"callback_url": "http://XXX.XXX.XXX.XX:8888/",
"fields": [
"feed"
],
"active": true
},
{
"object": "page",
"callback_url": "http://XXX.XXX.XXX.XX:8888/",
"fields": [
"picture"
],
"active": true
}
]
}
I've noticed various user comments reporting different concerns about the reliability of this API.
Also, here:
http://developers.facebook.com/docs/reference/api/page/
it says: "Note: Real-time updates are not yet supported for the total number of Page checkins."
...which I'm not sure what it means exactly.
For the record, my app's page I'm using for tests is:
http://www.facebook.com/pages/testgiamp/187148861354102?sk=wall
I want to use node.js to boost my Facebook applications performance. Imagine application that tries to compute who is you best friend on Facebook, fetching a lot of data from API calls - determining how many times your friends have posted to your wall, how many photos you have marked on together - so on.
So instead of running that calls one after one, as I do using PHP I have an idea to send them all together to Facebook using non-blocking, asynchronous nature of Node.js.
So overall execution time will be the time of most time consuming API call, but not the sum of execution time of the every call, right?
I try to use node-facebook-sdk (https://github.com/tenorviol/node-facebook-sdk) to make Facebook API calls and it seems to be that it's blocking, isn't it?
Just quick and dirty modification of example code, requesting 3 user profiles, seems that calls are not asynchronous, each sending to Facebook after previous has completed. Are there any way to avoid that?
Thank in advance!
var fbsdk = require('facebook-sdk');
var facebook = new fbsdk.Facebook({
appId : '_APPID_',
secret : '_SECRET_'
});
var i = 0;
setInterval(function() {
i++;
console.log("TICK " + i);
}, 500);
facebook.api('/100000997949108', function(data) {
console.log(data);
});
facebook.api('/1609464095', function(data) {
console.log(data);
});
facebook.api('/100000560820400', function(data) {
console.log(data);
});
This library will help you out with all things async. I hashed the particular method you would want to use for your problem, but the library as a whole is excellent at abstracting some of the more tedious (and ugly!) async patterns away. Great transitioning tool for those coming from procedural and you can take a peak under the covers if you want to learn some async patterns.
https://github.com/caolan/async/#parallel