Forum Discussion
Server not sending a response to Teams
I created a test messaging extension that's just supposed to go to a website link when clicked. I was able to get the app onto teams and install it to a channel, but when I try to use it or open it from the store, I get 'Unable to reach app. Please try again.' my ngrok server says "Waiting to receive a response from your server". My server code is below, I thought the callback(null, response, 200) at the bottom was supposed to send the response back to teams. Any ideas or advice is appreciated.
var request = require('request');
var util = require("util");
var restify = require('restify');
var builder = require('botbuilder');
var teams = require('botbuilder-teams');
var connector = new teams.TeamsChatConnector({
appId: "myAppId",
appPassword: "myAppPassword"
});
var server = restify.createServer();
server.listen(3978, function () {
console.log('%s listening to app2 %s', server.name, util.inspect(server.address()));
});
var inMemoryStorage = new builder.MemoryBotStorage();
var bot = new builder.UniversalBot(connector).set('storage', inMemoryStorage);
var stripBotAtMentions = new teams.StripBotAtMentions();
bot.use(stripBotAtMentions);
bot.dialog('/', [
function (session) {
builder.Prompts.text(session, 'Hi! What is your name?');
},
function (session, results) {
session.endDialog(`Hello ${results.response}!`);
}
]);
// this will reset and allow to receive from any tenants
connector.resetAllowedTenants();
// var bot = new builder.UniversalBot(connector);
server.post('/api/composeExtension', connector.listen());
server.post('/api/messages', connector.listen());
// server.post('/greetings', connector.listen());
server.post('/', connector.listen());
var composeExtensionHandler = function (event, query, callback) {
// parameters should be identical to manifest
console.log("Query Running");
var attachments = [];
try {
console.log('hit')
var card = new builder.HeroCard()
.buttons([{
type: "openUrl",
title: "Open Kloud",
value: 'kloud.com'
}]);
attachments.push(card.toAttachment());
} catch (err) {
console.log(err);
}
var response = teams.ComposeExtensionResponse
.result('list')
.attachments(attachments)
.toResponse();
// Send the response to teams
callback(null, response, 200);
//}
};
connector.onQuery('Open', composeExtensionHandler);
var composeInvoke = function (event) {
console.log(event);
};
connector.onInvoke(composeInvoke);
- Gousia_BegumMicrosoft
marcusyoung Could you please try the sample here for Message Extension and see if you are facing any issue?
- marcusyoungCopper Contributor
Gousia_Begum I'm getting a response, but now I'm getting TypeError: BotFrameworkAdapter is not a constructor. I botbuilder installed already and I've tried different versions of it.
- marcusyoungCopper Contributor
Fixed the problem by manually installing the latest version of botbuilder. Seems like the normal npm i was installing a previous version.