how to tell if user responded to my facebook request? - facebook-graph-api-v2.0

I don't really understand what i should do after invitable friends call. So this is the procedure till im stuck:
I have a facebook canvas app, but the app itself is mostly ios/android native so the canvas is for redirection only.
https://developers.facebook.com/docs/games/invitable-friends/v2.0
according to this:
*. i get the list of friends when i do the call (i did it)
*. i get the tokens, when i press a friend, a token is entering the array which is later used for "to" in the javascript api
*. i press send and do the invite.
Ok now i see this:
Rewarding the Sender
1)Upon sending the request, store the request id returned in the response from the Game Request Dialog and match it upon receipt to reward the sender.
2)Read all the requests for the receiver and reward the sender based on the ID in the "from" field.
What is the exact way to do those two ( 'and match it upon receipt to reward the sender' <- and what the hell does that mean? )?

Related

How can I find telegram user by id

I'm using telegram bot and can get user id from incoming message.
Sometimes I want to find users who communicate with telegram bot and write them message by myself.
I have only user id and have not some additional information about the user.
Can I somehow find users by id or anonimity with only id available is by design?
At least what I've been using...
Program your bot to send you a message with link to that user.
This can be done by using link in your message (must be used as message entity or inline keyboard button):
tg://user?id=<user_id>
Or in case you are using MarkdownV2 for formatting
[inline mention of a user](tg://user?id=<user_id>)
Then, by clicking on that link, you will open a user profile, where you can message your target.
Note, user can change his privacy settings, and disable mentions. In this case these links will not work.

Waiting for multiple user entries before sending API request

I am currently developing an application in flutter where the user types a text, which I send through an API POST request. I'm currently able to get the text and send it and get a response, it works fine.
The thing is, I want to allow the user to write multiple messages successively, before sending the request to the API; something like that:
user types message
user presses send message
wait to see if user is typing another message before sending the API request
if user is typing, wait till he presses send, and make one API request with both messages
I don't know if that is possible to do in flutter. I read about debounce() method of different packages but i saw that it works witha delay, does it also work with checking for typing conditions?
Any help is appreciated, thanks!

Identify unique user in Dialogflow V1

So I am testing out Dialogflow and one of the first questions I have is: how does my bot know who it is talking to? I need to identify a user and keep that information for as long as I can. The basic scenario being:
User starts his/her first conversation.
Chatbot send a fulfillment request to the server trying to match a user within its own database.
The user is found, the information (as a JWT or some other token) is sent back to Dialogflow and stored there for further communication. In reality, this part would involve asking for user email, sending a verification code to that email and then verifying the user with the code.
User then starts chatting with a bot and all fulfillment requests get the unique token stored for this very user, so that my REST API knows which user is being served with the response.
Couldn't find anything about it in the docs (maybe I am looking in the wrong places).
There will be several integrations, like Messenger, Viber, Telegram. I dunno, maybe those APIs add some unique information on the user?...
Thanks for the help!
Sorry, I know it's been a while, but maybe this will help someone else.
The right solution here is a user id, not a session id. A user id is provided by the chat platform (Facebook, Slack etc) and is consistent across sessions for the same user.
To get the user id, go to the Fulfillment tab, enable the editor and use a function like so:
let r = request.body.originalDetectIntentRequest
//this makes sure that you're on an integration
if (r["source"]){
return r.payload.data.sender.id;
}
To tie together ids from different platforms, you probably have to have some kind of log-in process every time you encounter a new id on a platform.
Pop,
Sessions are built in already into DialogFlow requests to your fulfilment service, if you check the payload you will find a sessionId, it remains the same for the same client until it expires.
However if you want to identify the user from any of the clients that you can connect to DialogFlow like Messenger then from the same request payload to you you will notice that there is an object named originalRequest that is only available when requests are coming from those clients.
You can personalize those users response eg using their FB firstname in a message to them.

Login and Verify with only phone number using Nexmo or Twilio

This is an authentication flow, which logs in the user with only the phone number provided (Whatsapp style). The Steps are:
User enters phone number and sent to server.
Server generated 4 digit random key, and save the pair (phone,key) in DB.
Server asks 3rd party SMS service to send key to phone.
SMS service sends message.
User enters the key from sms, and together with phone, sent to server.
Server checks the pair against the DB.
If pair exists, server sends back a token for further calls.
What I am trying to understand is where services like Twilio and Nexmo fit in (or replace parts of the flow).
From what I understand, looking at Nexmo for example,
I can replace steps 2 and 3 with an API call to:
https://api.nexmo.com/verify/
and save the request_id from the response in the DB as pair (phone,request_id).
And now, when the user enters a 4 digit code and sends it back,
I need to call:
https://api.nexmo.com/verify/check/json
providing it with request_id and code.
But where do I get the request_id?
Do the server needs to send it back to the client, the moment it gets it from Nexmo?
I can't see the benefits of using Nexmo here, what will it save me?
Answer to your first question: the request_id is part of the response to the first verify API call. See: https://docs.nexmo.com/index.php/verify/verify
As to what are the benefits of Nexmo here, I believe you have two options:
Generate your own code, use Nexmo to text it to your user, have the user submit the code back to your application, verify code against your own database.
Use Nexmo verify service to generate and send the code to the user, store the returned request_id in your db, have user submit code to your application, call Nexmo verify API to validate code.
In some ways the first option is easier as it is less API calls. However the benefit of the second option, using Nexmo Verify, is that they provide a whole lot more capabilities into the service to fall back to a voice call if SMS isn't working, filter out virtual phone numbers to prevent spam, you don't have to pay for failed SMS attempts, reporting/analytics, etc. etc.
Hopefully that helps a little.

How can I send message to specific chatID?

I have chatId and want send messages while execute some tasks from java code. I found this explain on telegram "Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/ links or username search to find your bot." But my task works good when I use https request directly from browser. My bot perfectly answer for requests but how I can do this without user request?
I can not truly understand your case!
Anyway, your bot can send a message to a chat ID Only if the user witch blongs to the specified chat ID added your bot (send start to a bot).
and if it happened then send your message with
/sendMessage