[FB Messenger] Getting 400 "Bad Request" error when sending messages to Messenger channel?
Bot Info
-
App ID: 424cfe9b-956f-4bf6-b62d-bc461a1e8d66
-
SDK Platform: Node.js
-
SDK Version: 3.11.0
-
Active Channels: FB Messenger
-
Deployment Environment: ngrok
Issue Description
Had a bot working locally with ngrok. all of a sudden I begin to receive errors with my bot.
I receive incoming messages, but only on reply I get the following error. Something is now broken with the callback for the bot to send a message back to Facebook.
Error: Request to 'https://facebook.botframework.com/v3/conversations/xxxxxxx' failed: [400] Bad Request
at Request._callback (/dev_env/instabot/v/app/node_modules/botbuilder/lib/bots/ChatConnector.js:532:46)
at Request.self.callback (/dev_env/instabot/v2/app/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:192:7)
at Request.<anonymous> (/dev_env/instabot/v2/app/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:189:7)
at IncomingMessage.<anonymous> (/dev_env/instabot/v2/bot/app/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:291:19)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:186:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
This error is in my development environment only. I have a production bot, on a different page, and have not seen this issue.
I attempted to upgrade to latest version of bot framework which did not fix.
It seems that this is a real issue, either between MS and FB. An additional note is that the First and Last name were no longer being passed on the broken page.
I set up a new Facebook page and created a new fb app with the exact same code and it works as expected.
I'm documenting this because it sucks to spend 3 hours troubleshooting a random problem, it's something that the team at MS should look into, also if it happens in a prod environment I would be F*CKED...
Code Example
var restify = require('restify');
var builder = require('botbuilder');
// Create bot and add dialogs
var connector = new builder.ChatConnector({
appId: 'xxxx',
appPassword: 'xxxxx'
});
var bot = new builder.UniversalBot(connector);
bot.dialog('/', function (session) {
console.log( session.message.text)
session.send('Hello Universe');
});
// Setup Restify Server
var server = restify.createServer();
server.post('/', connector.listen());
server.listen(process.env.port || 4040, function () {
console.log('%s listening to %s', server.name, server.url);
});
Reproduction Steps
- Send message to bot.
Expected Behavior
Bot returns "Hello Universe"
Actual Results
Error: Request to 'https://facebook.botframework.com/v3/conversations/xxxxx' failed: [400] Bad Request
at Request._callback (/dev_env/instabot/v/app/node_modules/botbuilder/lib/bots/ChatConnector.js:532:46)
at Request.self.callback (/dev_env/instabot/v2/app/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:192:7)
at Request.<anonymous> (/dev_env/instabot/v2/app/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:189:7)
at IncomingMessage.<anonymous> (/dev_env/instabot/v2/bot/app/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:291:19)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:186:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Also seeing this, but with Skype. WebChat seems to work fine.
Error: Request to 'https://smba.trafficmanager.net/apis/v3/conversations/xxxxxxxx/activities' failed: [400] Bad Request
--
| at Request._callback (/opt/app-root/src/node_modules/botbuilder/lib/bots/ChatConnector.js:532:46)
| at Request.self.callback (/opt/app-root/src/node_modules/request/request.js:186:22)
| at emitTwo (events.js:106:13)
| at Request.emit (events.js:191:7)
| at Request.<anonymous> (/opt/app-root/src/node_modules/request/request.js:1163:10)
| at emitOne (events.js:96:13)
| at Request.emit (events.js:188:7)
| at IncomingMessage.<anonymous> (/opt/app-root/src/node_modules/request/request.js:1085:12)
| at IncomingMessage.g (events.js:292:16)
| at emitNone (events.js:91:20)
| at IncomingMessage.emit (events.js:185:7)
Same problem from today, i have this for ALL the requests:
Error: Request to 'https://facebook.botframework.com/v3/conversations/1588505027902870-1453809838200948/activities/mid.%24cAAVwyFuNfTFl7j8j4lfvPnbch7_k' failed: [400] Bad Request
at Request._callback (D:\home\site\wwwroot\node_modules\botbuilder\lib\bots\ChatConnector.js:532:46)
at Request.self.callback (D:\home\site\wwwroot\node_modules\request\request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.
On Bot service channels Tab i got 3 issues for fb messenger: "error":{"message":"Error validating application. Application has been deleted.","type":"OAuthException","code":190,"fbtrace_id":"DuHlYeP3Ao
Please help me !!! This bot is on production and running over a real restaurant fan page.
Not sure if 100% the same, but I also try to connect from NodeJS code, and DirectLineJS to send activity to my SkypeBot via valid configured DirectLine channel, and I provide valid conversationId, but DirectLine API can't find the conversation.
I debugged DirectLine, and I guess, it's because it's kinda virtual chat, that is why it's ok for me for now. But just in case here is debug from Heroku:
2017-11-15T22:36:30.293915+00:00 app[web.1]: Error: Request to 'https://directline.botframework.com/v3/conversations/19%3A0e...........2%40thread.skype/activities'
failed: [400] Bad Request
2017-11-15T22:36:30.293928+00:00 app[web.1]: at Request._callback (/app/node_modules/botbuilder/lib/bots/ChatConnector.js:532:46)
2017-11-15T22:36:30.293929+00:00 app[web.1]: at Request.self.callback (/app/node_modules/request/request.js:186:22)
2017-11-15T22:36:30.293930+00:00 app[web.1]: at emitTwo (events.js:126:13)
2017-11-15T22:36:30.293930+00:00 app[web.1]: at Request.emit (events.js:214:7)
2017-11-15T22:36:30.293931+00:00 app[web.1]: at Request.<anonymous> (/app/node_modules/request/request.js:1163:10)
2017-11-15T22:36:30.293932+00:00 app[web.1]: at emitOne (events.js:116:13)
2017-11-15T22:36:30.293932+00:00 app[web.1]: at Request.emit (events.js:211:7)
2017-11-15T22:36:30.293933+00:00 app[web.1]: at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:1085:12)
2017-11-15T22:36:30.293933+00:00 app[web.1]: at Object.onceWrapper (events.js:313:30)
2017-11-15T22:36:30.293934+00:00 app[web.1]: at emitNone (events.js:111:20)
I'm not sure if DirectLine is bets way to connect/send message to real Skype Chat. I suspect, DirectLineJS is good only for WebChat-like pages, where every page refresh recreate conversation. NOT sure at all... what I'm writing, because Bot Docs is so huge, lot of variants, looks clear, but when I start coding, faced with lot of issues
I have feeling, that I'm doing smth wrong, recently started with bots. But almost 3 weeks, I strugling with either 401, or 404, or 400 or CORS or smth else. And looks simple task - send a request to Bot API -> Bot send a message to channel chat.
In fact, my idea is to send non-reply message to Skype chat, where my bot is added. That is why I play with code around this doc info. But DirectLine is also looks similar approach.
@dundas Can you login to https://dev.botframework.com/bots/ and go to your bot page and refresh and check the logs in the health tab and send a screen shot to better debug the error.
@Aashish-Amber it's empty. And in case u don't believe me:

Here is my JS code for simple DirectLine usage
// https://docs.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-direct-line-3-0-send-activity
function sendAnActivity_via_DirectLine_directly(){
$.ajax(`https://directline.botframework.com/v3/directline/conversations/${conversationId}/activities`, {
method: 'post',
data: {
"type": "message",
"from": {
"id": "user1"
},
"text": "eat"
},
_contentType: 'application/json', // if provided, no response at all
_crossDomain: true,
beforeSend: function(xhr){
xhr.setRequestHeader('Authorization', 'Bearer ' + secret);
// xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
},
_headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
// 'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
// 'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token',
// 'Access-Control-Allow-Credentials': 'true'
},
complete: function(xhr, textStatus) {
// console.log(xhr, textStatus)
},
success: function(data, textStatus, xhr) {
// console.log(data, textStatus, xhr)
},
error: function(xhr, textStatus, errorThrown) {
console.log(xhr, textStatus, errorThrown);
// {
// "error": {
// "code": "BadArgument",
// "message": "Unknown conversation"
// }
// }
}
}).then(function(){
});
}
sendAnActivity_via_DirectLine_directly();
Request URL:https://directline.botframework.com/v3/directline/conversations/19:[email protected]/activities
Request Method:POST
Status Code:404 Not Found
Remote Address:40.127.139.252:443
Referrer Policy:no-referrer-when-downgrade
Request Headers:
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9,pl;q=0.8,uk;q=0.7,ru;q=0.6
Authorization:Bearer gUY0M............_T7SItaR-vnVYQ
Cache-Control:no-cache
Connection:keep-alive
Content-Length:40
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:directline.botframework.com
Origin:http://localhost:8080
Pragma:no-cache
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3265.0 Safari/537.36
Response Headers:
HTTP/1.1 404 Not Found
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 90
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
Access-Control-Allow-Origin: *
Request-Context: appId=cid-v1:91e46abb-4ce5-4d98-9375-02378f649011
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000
Date: Thu, 16 Nov 2017 09:37:39 GMT
Form Data / payload:
type:message
from[id]:user1
text:eat

@alundiak The direct line is a channel, and so is skype. The direct line channel cannot be used to connect to the skype channel. Please open a new issue.
@dundas You might need to re-configure the facebook channel for your bot:
{"error":{"message":"Error validating access token: The session has been invalidated because the user changed their password or Facebook has changed the session for security reasons.","type":"OAuthException","code":190,"error_subcode":460,"fbtrace_id":"EnJYLsXtpqR"}}
--