So I have created Messenger bot. Is there a way to receive webhook when someone who was interacting with bot has blocked it? Similar to how you can set up webhook when someone uninstalls facebook app.
When a user first interacts with the bot I store his information in the database. If he decides to block the bot, I want to delete that row from the database so receiving messenger_id would be completely enough.
I read through FB docs but did not find anything useful. Would appreciate if someone could help.
You will receive an error code when you try to message the user from your bot. Probably something similar to this:
{
"error": {
"message": "This Person Cannot Receive Messages: This person isn't receiving messages from you right now.",
"type": "OAuthException",
"code": 10,
"error_subcode": 2018108,
"fbtrace_id": "BLBz/WZt8dN"
}
}
Try going through your response logs finding that user PSID to see the exact error you are getting, but it should be very similar to the above.
So what you have to do is update the user when you get a response like this consistently, perhaps set a counter or build a rule for when you decide is enough to remove the user form your DB or disable. More info on the errors here:
https://developers.facebook.com/docs/messenger-platform/reference/send-api/error-codes
Related
I'm setting up a Slack App to post messages via the Web API and using a bot OAuth token from an ASP.NET web app, and one of the requirements is for the Slack app to be able to return a relevant value for when a user has last read their messages in their DM with the Slack bot. This is to track which messages require updating or reposting.
At first I figured you can send a request with the conversations.info method to get the "last_read" property from the JSON response. And if I was using the user OAuth token (with "xoxp-...") in the request for any direct message opened by the user associated with the token, I would get a value such as "1571423219851.000000" milliseconds.
But when I would use the bot token (using "xoxb-...") to check a DM to a user, it would have for the "last_read" field in zeros.
The steps to reproduce the issue is:
Have the Slack App open a direct message with a user (in this case with myself, as the user OAuth token is set to my account) by conversations.open method, supplying the bot user token and users=(your_slack_id). Save the DM id for later.
https://api.slack.com/methods/conversations.open/test
"ok": true,
"no_op": true,
"already_open": true,
"channel": {
"id": "DP4NRGLNE"
}
Send a message to propogate the message window using the DM id.
https://api.slack.com/methods/chat.postMessage/test
Test with the conversations.info method using the bot token and DM id.
https://api.slack.com/methods/conversations.info/test
However, when I run the method, I would get a response like this.
"ok": true,
"channel": {
"id": "DP4NRGLNE",
"created": 1571404761,
"is_archived": false,
"is_im": true,
"is_org_shared": false,
"user": "UN4F12QH7",
"last_read": "0000000000.000000",
"latest": {
...
},
"unread_count": 3,
"unread_count_display": 3,
"is_open": true,
"priority": 0
}
Expected: The "last_read" field is set to some value, i.e. "1571404761.000000", with unread_count set to 0.
Actual: The "last_read" field is still set to "0000000000.000000" (and unread_count not resetting to 0), despite having message history in the direct message, and having acknowledged "Mark read" for new messages/ physically opened the chat log and scrolled down over the new messages.
The suspicion is that using the user OAuth token will return a relevant last_read value because a user themselves will set a last_read timestamp in a given conversation while a Slack bot doesn't ever set the "last_read" field for a conversation they are part of (i.e. a user doesn't need to know when the bot itself last read the chat?). Though if it that was the case, then why is using a bot token unable to see a set value for the last_read field for a user in their DM? That's sort of where this question comes from (and the confusion).
This is probably an incorrect theory, but Slack documentation doesn't seem to address this concern, so any suggestions would be welcome.
EDIT: After looking closer at the documentation, it would appear that the child family of methods im doesn't have a concept of im.info, hence the default value of 0 is set for a dm.
As the documentation states about the last_read attribute for channel types:
last_read is the timestamp for the last message the calling user has
read in this channel
If you use the bot token to call conversations.history then the calling user is the bot user, which apparently has not read any of the messages yet.
So this is not a bug, but works as intended.
I'm having an issue with FCM on flutter. I have implemented messaging from my server so I'm storing my phone token for each user.
The thing is that when a user logs in for the very first time everything works properly, messages are being sent and user gets notified.
If I do not use the app during the weekend, on Monday I try to send a message by doing some actions on my app but messages are not being sent. I can see my token stored properly in my database.
I'm using firebase_messaging 2.1.0 for flutter.
This is how I get my token
_fireBaseMessaging.getToken().then((token){
_myPhoneToken = token;
});
1-I know token may change when:
App deletes Instance ID
App is restored on a new device
User uninstalls/reinstall the app
User clears app data
But none of this happens.
Any advice on how to handle this scenario? thanks in advance.
UPDATE
Provided you have setup the FCM sdk the right way (but you said that it works the fist time you install the app, so I guess so).
Provided that you are sure that the device_token you are using is the one of the device on which you are expecting to receive the notification (check if it's still the same), you should get on this device your notification quite soon if you use "priority" : "high".
{
"to" : "device_token",
"priority" : "high",
"notification" : {
"sound": "default",
"body" : "Test Notification body",
"title": "Test Notification title"
}
}
This method call
_firebaseMessaging.getToken().then((String token)
return always the new token even if it has been updated. So if you print this out on your device and you send a notification on this token without error, there's no reason why you should not get the token if the device has a valid internet connection active.
It's true that the device token can change during time. If you uninstall and reinstall the app, you can see the token will change and if you try to send a notification on the old one, you will get an error.
If instead the token will change during application lifetime, you can be notify on your server side by listening:
_firebaseMessaging.onTokenRefresh.listen((newToken) {
_fcm_token = newToken;
// send the new fcm to your server
});
So first of all I suggest you to be able to send a notification to a device with Postman. Check if the token you are using is still the one on the device. Then you can try to uninstall and reinstall the application and try to use the old token. You will get an error. Then try to send to the new one, and you should get your notification.
Then wait for some days and try again, check if the token has changed or not and if it's not changed you should be able to send the notification without problems with the same token.
Also be aware that data message on Android if the app is terminated are still not supported.
Some networks/router/mobile can cut the connection between firebase library and firebase server due to inactivity (5min without message). This cut may be detected by the library up to 30min (FCM heatbeat interval).
These are some links discussing this issue:
https://github.com/firebase/quickstart-android/issues/307
Android: Delay in Receiving message in FCM(onMessageReceived)
I contacted firebase support but they told that since the issue is caused by external part they cannot fix it (I suggest decreasing heartbeat interval ...)
I fixed it in android using an interval job which apply these instructions:
context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));
You may write this specific code for Android side and should find something similar for ios side.
I'm trying to set my bot's typing status by sending the following POST request (based on the API docs):
https://api.telegram.org/bot{{botToken}}/setTyping
{
peer: {{chat_id}},
typing: true,
action: 'sendMessageTypingAction'
}
I've tried a few variations of it, such as changing the url to be /messages.setTyping and sending the action as {"_":"sendMessageTypingAction"} as seen here, but all I get is:
{
"ok": false,
"error_code": 404,
"description": "Not Found: method not found"
}
Anyone know what I'm doing wrong?
Thanks to #tashakori for pointing me in the right direction towards the Bot API. For posterity, what I needed to do was:
https://api.telegram.org/bot{{botToken}}/sendChatAction
{
chat_id: {{chatId}},
action: 'typing'
}
The link you have mentioned above belongs to Telegram Core APIs which is used for handling ordinary accounts of Telegram. These so-called Core APIs are not related to Telegram Bot APIs.
The only API that is somehow similar to SetTyping for bots is AnswerCallbackQuery, which can be used only when responding to the user's interaction with inline keyboards. (you can send a text to the user, saying that there is a process running in the background and whenever the user's answer is ready, you can send it using APIs like sendMessage)
I'm trying to setup my Google Identity Toolkit so users can reset their passwords. I'm following the documentation here: https://developers.google.com/identity/toolkit/web/required-endpoints#send_email_url
I'm using the PHP Gitkit Client outlined here: https://github.com/google/identity-toolkit-php-client/blob/master/src/GitkitClient.php
Specifically the function getOobResults() on line 307 seems to be unhappy for some reason. Here's where I'm at:
User sets up account and logs in successfully
User then logs out and starts to log back in, enters email in and clicks "Forgot password"
reCaptcha is shown, click check box and then hit continue
At this point my 'Send Email URL' endpoint (gitkitEmail.php) is successfully called and the following POST is set to it (dropping the full '&response' param since it goes on for a while):
action=resetPassword&email=xodfebefa%40nada.ltd&challenge&response=03ACgFB9tGlNt2KAGhrVY....
I then take that string and parse it using parse_str(); since getOobResults() is looking for an array. However, response I get back is always:
{
"response_body": {
"error": "CAPTCHA_CHECK_FAILED"
}
}
I searched around but can't find any details on this error. Any help would be appreciated. I don't have a reCaptcha setup anywhere on my site, unsure if this is expecting me to do that and that's why it's failing? Also, I did bump all my code to a production environment and got the same error there as I did on my localhost.
I've created new bot for Telegram. I've set /setinline in BotFather for my bot. I've added a webhook that is called when I send a message to bot but this webhook is not called if I write something in the bot chat without send any message.
Any idea how to solve?
Yes, it does, probably you're inspecting the wrong param, it will call the same webhook, first remember you set the webhook by doing:
https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=<YOUR_URL>
and like you mentioned, you need to enable /setinline through BotFather, then it will call your endpoint with a message with the following body:
{
"query":"tex",
"from": {
"username":"user",
"first_name":"firstname",
"last_name":"lastname",
"id": 8888888,
"language_code":"en-US"},
"id":"7777777",
"offset":""
}
Remember it will call your endpoint on key-up you may receive a ton of request.