Reputation: 1173
Using emulator as channelId and updating to SDK 3.13.1 works for me.
I tried following steps mentioned in this link. This has two parts. One is creating the token and second is to send a message to the bot. POSTMAN request leads to 500 Internal Server Error and ERROR: ChatConnector: receive - invalid signing key or OpenId metadata document in the code.
Create token
curl -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -H 'cache-control: no-cache' -H 'content-type: application/x-www-form-urlencoded' -H 'postman-token: 792660ab-b1aa-0cbd-edab-9b3847c170d5' -d 'grant_type=client_credentials&client_id=8c082f92-fb38-4841-a29f-339eb315f7aa&client_secret=vxcihBT2679%7C(%23puEXBPT1!&scope=8c082f92-fb38-4841-a29f-339eb315f7aa%2F.default'
Send a message
curl -X POST https://1c36f336.ngrok.io/api/messages -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ing0Nzh4eU9wbHNNMUg3TlhrN1N4MTd4MXVwYyJ9.eyJhdWQiOiI4YzA4MmY5Mi1mYjM4LTQ4NDEtYTI5Zi0zMzllYjMxNWY3YWEiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vZDZkNDk0MjAtZjM5Yi00ZGY3LWExZGMtZDU5YTkzNTg3MWRiL3YyLjAiLCJpYXQiOjE1MTIxOTg2NjcsIm5iZiI6MTUxMjE5ODY2NywiZXhwIjoxNTEyMjAyNTY3LCJhaW8iOiJZMk5nWUZEOHRySzgvZk9XcDF2L1BMM2JibnRGRGdBPSIsImF6cCI6IjhjMDgyZjkyLWZiMzgtNDg0MS1hMjlmLTMzOWViMzE1ZjdhYSIsImF6cGFjciI6IjEiLCJ0aWQiOiJkNmQ0OTQyMC1mMzliLTRkZjctYTFkYy1kNTlhOTM1ODcxZGIiLCJ1dGkiOiJXLWdYbXpPSkxVYWdzSFZUbXBJd0FBIiwidmVyIjoiMi4wIn0.G705tzQIU5Mh6IROtXkIwm8Q9AKZ_q-VOtJuuozqP-ekhWoKc0HpcdhgBlnaMsMHKoM0RWhUlXn27xCfK46vEE9IZlkjcAh7huhvlWNtW8IP5w7QiL3JCSTYKCtBXZq-VKeWctNWR9M8Y9Ry4dyiEdcDMcHWrbOUqR6nXvlwG76GSR4YilqzMWdSW6t5Pep3hwOw07DSargYP0pDAnWAg3pWHnhcJ185533I1VVXEIuc_CK-RmP9qhUAScEbYkpp_7l75bVWzxKv-3E1UOG4SBj6UzfH47X5kwz_njn1kAJcrqBvP3s_CjS4qUdDSNARtxGZ3UQWj49UBKosqar0dg' -H 'cache-control: no-cache' -H 'content-type: application/json' -H 'postman-token: 3a74ce00-2da7-d674-5e4c-083f54ed30ff' -d '{ "type": "message", "id": "mid.$cAAGEkG8MNm1mOEBe-lgBvsWZbQUc", "channelId" : "test", "conversation": { "id": "100023023852067-526013297749070"}, "from": { "id": "100023023852067" }, "recipient": { "id": "526013297749070" }, "serviceUrl": "https://1c36f336.ngrok.io", "text": "Hi message from postman !!!" }'
POSTMAN request should lead to 202 Accepted and bot receiving the message. Am I missing something or is there something wrong in the process? I saw some issues on load testing but none of them helped.
POSTMAN request leads to 500 Internal Server Error and ERROR: ChatConnector: receive - invalid signing key or OpenId metadata document in the code.
Upvotes: 1
Views: 1122
Reputation: 2606
After I added extended
field I got same error.
Not sure how that is related but replace
server.use(bodyParser.urlencoded({ extended: true }));
to:
server.use(bodyParser.urlencoded());
fixed the issue.
Upvotes: 1
Reputation: 8292
I was able to get this to work after:
1) adding a custom state client to the bot using botbuilder-azure
2) exposing the message sink, for receiving the bot response
3) changing the channelId to "emulator" (apparently node sdk doesn't handle 'test' channel)
curl -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -H "content-type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=MyMicrosoftAppId&client_secret=MyMicrosoftAppPassword&scope=MyMicrosoftAppId%2F.default"
curl -X POST https://e84a2f49.ngrok.io/api/messages -H "authorization: Bearer TokenFromPreviousCall" -d "{ \"type\": \"message\", \"id\": \"mid.$cAAGEkG8MNm1mOEBe-lgBvsWZbQUc\", \"channelId\" : \"emulator\", \"conversation\": { \"id\": \"100023023852067-526013297749070\"}, \"from\": { \"id\": \"100023023852067\" }, \"recipient\": { \"id\": \"526013297749070\" }, \"serviceUrl\": \"https://e84a2f49.ngrok.io\", \"text\": \"Hi message from postman !!!\" }"
Here is the app, for reference:
var restify = require('restify');
var builder = require('botbuilder');
var azure = require('botbuilder-azure');
var sqlConfig = {
userName: 'SqlServerUserId',
password: 'SqlServerPassword',
server: 'mySqlServer.net',
enforceTable: true,
options: {
database: 'BotDatabaseName',
table: 'BotDataTableName',
encrypt: true,
rowCollectionOnRequestCompletion: true
}
}
var sqlClient = new azure.AzureSqlClient(sqlConfig);
var sqlStorage = new azure.AzureBotStorage({ gzipData: false }, sqlClient);
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3980, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: "MyAppId",
appPassword: "MyAppPassword"
});
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector, function (session) {
session.send("You said: %s", session.message.text);
}).set('storage', sqlStorage);;
//message sink
server.post("/v3/conversations/:conversationId/activities/:activityId", function(Request, Response, next) {
next();
});
Upvotes: 2
Reputation: 327
Not sure if this will help, but if you're using the same "fromId" in every request for your load test, it might be relevant.
Previously I've had a similar issue that required me to use a unique "fromId" in each request, else a series of requests in rapid succession start to fail.
I raised this issue on github, and although it says "followed up offline" and "problem was with the bot code", it was actually due to using the same "fromId" in every request.
The issue is here: https://github.com/Microsoft/BotBuilder/issues/1176
Upvotes: 1