I understand that when using the Facebook Messenger API, you MUST respond with a 200 OK header after receiving any webhook event or else the API will keep resending the webhook event every 20 second until a 200 OK is received as stated here https://developers.facebook.com/docs/messenger-platform/webhook/#response
I responded with the 200 OK header with the code below
<?php
header('HTTP/1.0 200 OK');
//.. some define here
//check token at setup
if(isset($_REQUEST['hub_verify_token']) && $_REQUEST['hub_verify_token'] === HUB_VERIFY_TOKEN){
echo $_REQUEST['hub_challenge'];
exit;
}
else{
$input = file_get_contents('php://input');
//... further process
}
With this, the API is not receiving the 200 OK as it keeps resending the webhook multiple times (like 100 times) and new webhooks are not delivered but when I send a message to the sender_id, it delivers.
Below is just the last 3 of about 100 I kept receiving. What am I doing wrong?
{"object":"page","entry":[{"id":"2229337433988598","time":1553082378936,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082476255,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082569721,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082667807,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
{"object":"page","entry":[{"id":"2229337433988598","time":1553082753466,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}
Related
We are using Accept Hosted Redirect Methods for our payment.
Some transaction's webhook callback have responseCode 0.
But these transactions are listed as approved in ANET account.
In our webhook code , we are processing only the responses with responseCode 1.
But when we take the transaction details using the ANET PHP SDK(Method GetTransactionDetails ) , it returns response code as 1.
Can any one help us to identify why the responseCode parameter have value 0.
Response received via hook callback
{
"notificationId": "************",
"eventType": "net.authorize.payment.authcapture.created",
"eventDate": "2021-04-14T21:52:39.1188391Z",
"webhookId": "********************",
"payload": {
"responseCode": 0,
"authAmount": 115.00,
"merchantReferenceId": "******************",
"invoiceNumber": "**********",
"entityName": "transaction",
"id": "************"
}
}
During the day "2021-04-14T21:52:39.1188391Z" there is some update happens from the ANET Side. As per the feedback from the ANET Support team they are worked on the WEBHOOK section exactly on the same day
I have an AWS Lambda function:
sendEmail.js
const AWS = require('aws-sdk');
const ses = new AWS.SES();
function sendEmail(subject, message, senderEmail) {
const params = {
Destination: {
ToAddresses: [
process.env.VERIFIED_EMAIL
]
},
Message: {
Body: {
Text: {
Data: message,
Charset: 'UTF-8'
}
},
Subject: {
Data: subject,
Charset: 'UTF-8'
}
},
Source: process.env.VERIFIED_EMAIL,
ReplyToAddresses: [senderEmail]
}
return ses.sendEmail(params).promise();
}
module.exports = sendEmail;
Called from
index.js
const sendEmail = require('./sendEmail');
exports.handler = async (event, context) => {
return sendEmail(event.subject, event.message, event.email).then((response) => { context.done(null, 'Email sent')});
};
I have the env. variable VERIFIED_EMAIL set to a personal e-mail that is verified by AWS/SES.
My test case:
{
"email": "redacted#outlook.com",
"subject": "desc",
"message": "Hello!"
}
Which passes and returns "Email sent" but I don't actually receive an e-mail. I've also deployed the API-GATEWAY and I can call the API w/ Postman and I receive the same "Email sent" message but no e-mail is actually sent.
I don't think it should be an issue with being in sandbox mode because the email I am sending it from is verified.
PS:
When Looking at the SES management console it says that the emails are being sent (they take up part of the 200 daily quota) and then that none of them were bounced or rejected but simply deliveries.
A few things you should check with your SES before diving deeper.
In sandbox mode both "source email address" and "destination email address" have to be verified. Instead a mail won't be delivered.
In case you verify Email Domain so appropriate dns and DKIM records have to be added in your domain. Plus additional whitelist clearance is assumed if you use corporate domains.
Your IAM AWS user should be permitted to execute SES api calls. Check your policies and roles. Check Secret Key and Secret Id you use.
There might be problems when you use inappropriate email types and email sending endpoints (eg you try to send "SingleTemplatedMessage" via "BulkTemplatedMessage" endpoint)
Check all this things first.
Then you might try something else. In my project we use AWS SDK based on java to interact between BE and SES. It provides logs containing message statuses (if a message was sent successfully, rejected, its id and other errors if they occurred)
Additionally to keep track on every single message you send you can set up SES-SNS to exchange with notifications. It's described in the following article
https://sysgears.com/articles/how-to-track-email-status-with-amazon-ses-and-amazon-sns/
Other problems might occur in your mail client (spam filters etc)
Follow the check list to troubleshoot SES email sending:
Check the SMTP credential is ok or not using code shared by AWS
Same credential using in multiple application/IP may not work
Use minimum mail configuration, if you do not know setting value remove it, do not leave it with NULL.
Set, $config['charset'] = 'UTF-8'; // // 'UTF-8', 'ISO-8859-15'
Set, $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r"
Additional Check
Make sure trying to send email to the same domain if SES account is Sandbox
Check all outbound with mail TCP port is open
If using NATgateway Check both inbound and outbound with mail TCP port is open in open for the mail sending instance in it.
I seem to have a problem when responding to incoming messages via the Slack Events API (im.message event).
When a user (in this case UQ364CBPF) sends a message to my App Home, the events API correctly posts an event to my backend (=first line in the logs below).
I respond to the event with an HTTP 200 OK, and in my code (see below), I trigger a response from my Bot User.
This response is sent correctly in Slack.
But: after that, the events API keeps posting events that my own bot user has posted a message in this channel...
Also, where the events are usually posted only 3 times, these events just keep being posted non-stop. Even though the bot user only sent one response message in Slack.
User UQ364CBPF has posted message: I'm typing a message to my Slack bot. in DQ5FF35N2 of channel type: im
[26/Dec/2019 15:16:30] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ5FF35N2 of channel type: im
[26/Dec/2019 15:16:32] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
[26/Dec/2019 15:16:33] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
[26/Dec/2019 15:16:35] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
[26/Dec/2019 15:16:37] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
[26/Dec/2019 15:16:39] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
[26/Dec/2019 15:16:40] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
[26/Dec/2019 15:16:42] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
[26/Dec/2019 15:16:43] "POST /slack/events/ HTTP/1.1" 200 0
User UQ5529KTR has posted message: Thank you for your message! We will get back to you soon! in DQ3KX0NPJ of channel type: im
In my code, this is part of a bigger function that processes Slack events, the relevant part:
#csrf_exempt
def slack_events(request):
if request.method == 'POST':
json_data = json.loads(request.body)
event_callback_type = json_data['event']['type']
if event_callback_type == 'message':
user_id = json_data['event']['user']
text = json_data['event']['text']
channel_id = json_data['event']['channel']
channel_type = json_data['event']['channel_type']
timestamp = json_data['event']['ts']
print ('User ' + user_id + ' has posted message: ' + text + ' in ' + channel_id + ' of channel type: ' + channel_type)
slack_message_received(user_id, channel_id, channel_type, team_id, timestamp, text)
return HttpResponse(status=200)
There is nothing in here (or in the function slack_message_received) could trigger this recurring flow.
So
1. Is it strange behavior that Slack is bombarding me with all these
POST requests from my own bot user?
2. Can I avoid this behavior, other than filtering out my own Bot User ID and ignoring these requests on backend side?
It's standard behavior of the Events API that your bot will receive all message events, including from it's own posts. And by reacting to them you have created and endless loop.
To address this issue you need to stop reacting to the bot's own messages by filtering them out as you suggested in #2. That is the standard approach.
The easiest is to just filter out all bot messages, if you don't need to listen to other bots. Then you can just ignore all messages that have the subtype property. Alternatively you can of course filter our messages from your own bot.
I had the same issue. But when I printed the request, I couldn't find subtype so the solution above didn't work for me.
log detail showing what is in the request I receive. There was no subtype
Instead, I noticed that messages from bot had bot_id and messages from users didn't.
Therefore, my solution was like this:
#slack_events_adapter.on("message")
def say_hello(event_data):
print('EVENT_DATA')
print(event_data)
message = event_data['event']
# if the incoming message contains "hello" NOT CASE SENSITIVE, then respond with a designed message
# "subtype" doesnt help to filter bot's message event and user's message event
if message.get('bot_id') is None and 'hello' in ((message.get('text')).lower()):
channel_id = message['channel']
user = message['user']
message = "Hello <#%s>! :tada:" % user
slack_web_client.chat_postMessage(channel=channel_id, text=message)
else:
return
As #Phoebe said - while retrieving the events using
slack_message.get('event')
I didn't find a key as bot_id. I think this is an issue from Slack Events api.
As I see from the answer for this question: Karate will automatically send any cookies returned by the server in the next request.
But when I send the request I see two sets of cookies in Set-Cookie of response: one is auto-created and another is real, that returned from the server.
When I printed responseCookies, I saw there only automatic cookies
and for the next request new cookies are generated and sent.
For my test I need to use cookies returned after the first request because it is a call to login service.
Feature: Using cookies in next request
Background:
Given url baseUrl
And path LOGOUT_SERVICE_ENDPOINT
And configure headers = read('classpath:headers.js')
And def filename = 'classpath:resources/users/' + brand.toLowerCase() + '/user.json'
And json user = read(filename)
Scenario: Login
When def login = callonce read('classpath:features/login_service/login.feature') user
* print login.responseCookies
And request { arg1: '#(brand)'}
And method post
Then status 200
What is wrong in my feature or it is Karate issue?
two sets of cookies in Set-Cookie of response:
Maybe that is a bug in the server ?
Also try using "shared scope", because cookies also will be part of the "global" variables etc.
* callonce read('classpath:features/login_service/login.feature') user
* request { arg1: '#(brand)'}
If you are still stuck, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
I am trying to upload a large json data from android retrofit client to django rest api view.
For example(Json Data):
{'post_data': [{'x':'asdkdadlf fdsfsd','y':'This is a paragraph........ Ending paragraph', 'created_on':'2018-22-08'},
{'x':'asdkdadlf fdsfsd','y':'This is a paragraph........ Ending paragraph', 'created_on':'2018-22-08'},
{'x':'asdkdadlf fdsfsd','y':'This is a paragraph........ Ending paragraph', 'created_on':'2018-22-08'},
....
{'x':'asdkdadlf fdsfsd','y':'This is a paragraph........ Ending paragraph', 'created_on':'2018-22-08'},
{'x':'asdkdadlf fdsfsd','y':'This is a paragraph........ Ending paragraph', 'created_on':'2018-22-08'},
]}`
API Response output:
08-22 13:21:12.964 15628-16104/com.mml.wapp D/Abhay: Group type: 1 group name: REAL ESTATE PROPERTYfrom:+234 818 230 9054
08-22 13:21:12.995 15628-16104/com.mml.wapp D/Abhay: Total messages in db before adding current message: 100
08-22 13:21:13.062 15628-16104/com.mml.wapp D/deleteMessage: Deleted all messages
08-22 13:21:13.200 15628-16109/com.mml.wapp D/OkHttp: --> POST https://api.multiplymyleads.com/api/upload_whatsapp_msgs/ http/1.1
Content-Type: application/x-www-form-urlencoded
08-22 13:21:13.204 15628-16109/com.mml.wapp D/OkHttp: Content-Length: 73304
08-22 13:21:13.211 15628-16109/com.mml.wapp D/OkHttp: postdata=%7B%22%E2%80%AA%2B234%20818%20230%209054%E2%80%AC%22%3A%5B%7B%22group_type%22%3A%221%22%2C%22time%22%3A%222018-08-
... followed by a lot more of that
As far as I understand, data in above response seems huge, may be that's why its getting timeout error? As its not able to upload all data in one API call in given timeout time in server side.
What can we do to resolve above issue ?
I have checked API returning success response if reduce the json post_data size.
I am using retrofit 2.0 client in android side for API call.
After lot of research I solved it from android side using below spinet of code.
OkHttpClient client = new OkHttpClient();
client.newBuilder()
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60L, TimeUnit.SECONDS)
.writeTimeout(60L, TimeUnit.SECONDS);;
Which increases timeout for response.