Server not sending a response to Teams

%3CLINGO-SUB%20id%3D%22lingo-sub-1522163%22%20slang%3D%22en-US%22%3EServer%20not%20sending%20a%20response%20to%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1522163%22%20slang%3D%22en-US%22%3E%3CP%3EI%20created%20a%20test%20messaging%20extension%20that's%20just%20supposed%20to%20go%20to%20a%20website%20link%20when%20clicked.%20I%20was%20able%20to%20get%20the%20app%20onto%20teams%20and%20install%20it%20to%20a%20channel%2C%20but%20when%20I%20try%20to%20use%20it%20or%20open%20it%20from%20the%20store%2C%20I%20get%20'Unable%20to%20reach%20app.%20Please%20try%20again.'%20my%20ngrok%20server%20says%20%22%3CSPAN%3EWaiting%20to%20receive%20a%20response%20from%20your%20server%22.%20My%20server%20code%20is%20below%2C%20I%20thought%20the%20callback(null%2C%20response%2C%20200)%20at%20the%20bottom%20was%20supposed%20to%20send%20the%20response%20back%20to%20teams.%20Any%20ideas%20or%20advice%20is%20appreciated.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Evar%20request%20%3D%20require('request')%3B%0Avar%20util%20%3D%20require(%22util%22)%3B%0Avar%20restify%20%3D%20require('restify')%3B%0Avar%20builder%20%3D%20require('botbuilder')%3B%0Avar%20teams%20%3D%20require('botbuilder-teams')%3B%0A%0Avar%20connector%20%3D%20new%20teams.TeamsChatConnector(%7B%0A%20%20%20%20appId%3A%20%22myAppId%22%2C%0A%20%20%20%20appPassword%3A%20%22myAppPassword%22%0A%7D)%3B%0A%0Avar%20server%20%3D%20restify.createServer()%3B%0A%0Aserver.listen(3978%2C%20function%20()%20%7B%0A%20%20%20%20console.log('%25s%20listening%20to%20app2%20%25s'%2C%20server.name%2C%20util.inspect(server.address()))%3B%0A%7D)%3B%0Avar%20inMemoryStorage%20%3D%20new%20builder.MemoryBotStorage()%3B%0Avar%20bot%20%3D%20new%20builder.UniversalBot(connector).set('storage'%2C%20inMemoryStorage)%3B%0A%0Avar%20stripBotAtMentions%20%3D%20new%20teams.StripBotAtMentions()%3B%0Abot.use(stripBotAtMentions)%3B%0A%0Abot.dialog('%2F'%2C%20%5B%0A%20%20%20%20function%20(session)%20%7B%0A%20%20%20%20%20%20%20%20builder.Prompts.text(session%2C%20'Hi!%20What%20is%20your%20name%3F')%3B%0A%20%20%20%20%7D%2C%0A%20%20%20%20function%20(session%2C%20results)%20%7B%0A%20%20%20%20%20%20%20%20session.endDialog(%60Hello%20%24%7Bresults.response%7D!%60)%3B%0A%20%20%20%20%7D%0A%5D)%3B%0A%0A%2F%2F%20this%20will%20reset%20and%20allow%20to%20receive%20from%20any%20tenants%0Aconnector.resetAllowedTenants()%3B%0A%0A%2F%2F%20var%20bot%20%3D%20new%20builder.UniversalBot(connector)%3B%0A%0Aserver.post('%2Fapi%2FcomposeExtension'%2C%20connector.listen())%3B%0Aserver.post('%2Fapi%2Fmessages'%2C%20connector.listen())%3B%0A%2F%2F%20server.post('%2Fgreetings'%2C%20connector.listen())%3B%0Aserver.post('%2F'%2C%20connector.listen())%3B%0A%0Avar%20composeExtensionHandler%20%3D%20function%20(event%2C%20query%2C%20callback)%20%7B%0A%20%20%20%20%2F%2F%20parameters%20should%20be%20identical%20to%20manifest%0A%20%20%20%20console.log(%22Query%20Running%22)%3B%0A%20%20%20%20%0A%20%20%20%20var%20attachments%20%3D%20%5B%5D%3B%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20console.log('hit')%0A%20%20%20%20%20%20%20%20var%20card%20%3D%20new%20builder.HeroCard()%0A%20%20%20%20%20%20%20%20.buttons(%5B%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20type%3A%20%22openUrl%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20title%3A%20%22Open%20Kloud%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20value%3A%20'kloud.com'%0A%20%20%20%20%20%20%20%20%7D%5D)%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20attachments.push(card.toAttachment())%3B%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%7D%20catch%20(err)%20%7B%0A%20%20%20%20%20%20%20%20console.log(err)%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20var%20response%20%3D%20teams.ComposeExtensionResponse%0A%20%20%20%20%20%20%20%20.result('list')%0A%20%20%20%20%20%20%20%20.attachments(attachments)%0A%20%20%20%20%20%20%20%20.toResponse()%3B%0A%0A%20%20%20%20%2F%2F%20Send%20the%20response%20to%20teams%0A%20%20%20%20callback(null%2C%20response%2C%20200)%3B%0A%0A%20%20%20%20%20%20%20%20%2F%2F%7D%0A%0A%7D%3B%0A%0Aconnector.onQuery('Open'%2C%20composeExtensionHandler)%3B%0A%0Avar%20composeInvoke%20%3D%20function%20(event)%20%7B%0A%20%20%20%20console.log(event)%3B%0A%7D%3B%0A%0A%0Aconnector.onInvoke(composeInvoke)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1522163%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1522801%22%20slang%3D%22en-US%22%3ERe%3A%20Server%20not%20sending%20a%20response%20to%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1522801%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F714579%22%20target%3D%22_blank%22%3E%40marcusyoung%3C%2FA%3E%26nbsp%3BCould%20you%20please%20try%20the%20sample%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Ftree%2Fmaster%2Fsamples%2Fjavascript_nodejs%2F50.teams-messaging-extensions-search%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20for%20Message%20Extension%20and%20see%20if%20you%20are%20facing%20any%20issue%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1525258%22%20slang%3D%22en-US%22%3ERe%3A%20Server%20not%20sending%20a%20response%20to%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1525258%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F359599%22%20target%3D%22_blank%22%3E%40Gousia_Begum%3C%2FA%3E%26nbsp%3BI'm%20getting%20a%20response%2C%20but%20now%20I'm%20getting%26nbsp%3BTypeError%3A%20BotFrameworkAdapter%20is%20not%20a%20constructor.%20I%20botbuilder%20installed%20already%20and%20I've%20tried%20different%20versions%20of%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1527743%22%20slang%3D%22en-US%22%3ERe%3A%20Server%20not%20sending%20a%20response%20to%20Teams%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1527743%22%20slang%3D%22en-US%22%3E%3CP%3EFixed%20the%20problem%20by%20manually%20installing%20the%20latest%20version%20of%20botbuilder.%20Seems%20like%20the%20normal%20npm%20i%20was%20installing%20a%20previous%20version.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

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);

 

 

3 Replies

@marcusyoung Could you please try the sample here for Message Extension and see if you are facing any issue?

@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.

Fixed the problem by manually installing the latest version of botbuilder. Seems like the normal npm i was installing a previous version.