Botkit: How set service url for spawn a Microsoft Teams bot

Created on 19 Apr 2018  路  5Comments  路  Source: howdyai/botkit

Hi,

I鈥檓 trying to create a bot for microsoft team and I can't receive any message on it.

In the documentation it's written: "When spawning a bot for Microsoft Teams, you must pass in a serviceUrl field as part of the options parameter. The serviceUrl can be extracted from the incoming message payload at message.serviceUrl." but how do I get a message if the bot hasn鈥檛 spawned yet?

I tried to spawn the bot with a ngrok url to get the message.serviceUrl but I don't receive message anyway.

The bot work when I use botkit.botframeworkbot process.

var controller = botkit.teamsbot({
 clientId: process.env.MICROSOFT_APP_ID,`
 clientSecret: process.env.MICROSOFT_APP_PASSWORD,`
  storage: mongoStorage,
  debug: false,
});

var bot = controller.spawn({serviceUrl: process.env.NGROK_URL});

controller.setupWebserver(process.env.PORT || 3000, function(err, webserver) {
    controller.createWebhookEndpoints(webserver, function() {
        console.log("BOTKIT: Webhooks set up!");
    });
});

controller.on('message_received', function(bot, message) {
  console.log("message_received"); // Not printed
  bot = controller.spawn({serviceUrl: message.serviceUrl});
});
var controller = botkit.teamsbot({
 clientId: process.env.MICROSOFT_APP_ID,`
 clientSecret: process.env.MICROSOFT_APP_PASSWORD,`
  storage: mongoStorage,
  debug: false,
});

var bot = controller.spawn({serviceUrl: process.env.NGROK_URL});

controller.setupWebserver(process.env.PORT || 3000, function(err, webserver) {
    controller.createWebhookEndpoints(webserver, function() {
        console.log("BOTKIT: Webhooks set up!");
    });
});

controller.on('message_received', function(bot, message) {
  console.log("message_received"); // Not printed
  bot = controller.spawn({serviceUrl: message.serviceUrl});
});
Microsoft-Teams-related help wanted

Most helpful comment

Every doc I see seems to be saying "get the serviceURL from the conversation", which is chicken and egg if there is no existing conversation(s). If a bot wants to initiate a new conversation with a new user, where would the serviceURL come from?

All 5 comments

Are you using the starter kit? https://glitch.com/edit/#!/botkit-teams

You have the route for the serviceUrl there over in https://github.com/howdyai/botkit-starter-teams/blob/master/components/routes/teams.js#L7

To elaborate on @peterswimm's answer -- you get the serviceUrl from the incoming messages. You have to store it for later use.

Thanks for responses, i didn't used starter kit and with it, it's works. :)

Every doc I see seems to be saying "get the serviceURL from the conversation", which is chicken and egg if there is no existing conversation(s). If a bot wants to initiate a new conversation with a new user, where would the serviceURL come from?

I agree the documentation could definitely be improved.

Bots can be set up with a Bot endpoint address.

Whenever the app is installed by a user this endpoint will be called and sent a conversationUpdate event. This event contains the serviceUrl.

You can also go one step further and use the Microsoft Graph Api to automatically install Teams applications for users.

One question I have that isn't clear is whether the serviceUrl is User specific or Teams specific (e.g. could I potentially have a different serviceUrl for each user, or is it OK to store it on a per-teams basis).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GautierT picture GautierT  路  3Comments

TheJimFactor picture TheJimFactor  路  4Comments

iworkforthem picture iworkforthem  路  3Comments

matueranet picture matueranet  路  4Comments

benbrown picture benbrown  路  3Comments