Search code examples
botframeworkmicrosoft-teams

Bot Builder SDK4 - Microsoft Teams Extensions + bot framework emulator


I'm starting to developp a bot for microsoft teams using microsoft bot builder sdk v4 and the extension for teams (v4 - beta1) in typescript (node.js), and I want to test him. For that, in local, I've dowloaded the bot framework emulator v4. I would try, for the begining, to make a simple echo bot, but with proactive answer, like that :

'''javascript

const teamsContext = TeamsContext.from(context);
const convRef = TurnContext.getConversationReference(context.activity);
const tenantId = teamsContext.tenant.id;

var text = "You said : " + context.activity.text + "\n memberId : " + context.activity.from.id + "\n memberName : " + context.activity.from.name +
                        "\n channelId : " + context.activity.channelId;
const members = adapter.getConversationMembers(context);
                    await adapter.createConversation(convRef, async (newContext) => {
                        await newContext.sendActivity(text + "\n" + JSON.stringify(members));
                    });

'''

But, when I try it on the emulator, I obtain this error : [onTurnError]: TypeError: Cannot read property 'tenant' of undefined. I suppose that the general context cannot be "translate" in a teams context because of the emulateur. Is it possible to test the bot without deploy it, like custom http request, or should I to deploy it ?


Solution

  • If you want to test your bot in Teams you will need to create a bot in Azure. You don't necessarily have to deploy to it as you can use Azure Relays or ngrok to run your locally hosted bot thru Azure and, subsequently, in Teams.

    Whichever flavor you choose, you will run that service locally on your machine alongside your bot. The generated endpoint you will place into the Messaging Endpoint of your Azure bot's settings blade. Be sure to append the generated endpoint with '/api/messages' (e.g. https://testrelay.servicebus.windows.net/myrelay/api/messages).

    enter image description here

    You will also want to be sure to include the MicrosoftAppId and MicrosoftAppPassword from your Azure bot in your locally hosted bot. You should record these when your Azure bot is created. If you miss doing so, you can click the 'Deployments' blade in the resource group, select your deployed bot, then Inputs. Your values are stored there as 'appId' and 'appSecret'.

    enter image description here

    At this point, your bot should be good to go. You will need to register your bot in Teams before it will be recognized. You can add it via Channels in your Azure bot which will make it only accessible to you, or you can add it as an app via the Teams app which requires building and uploading a Teams app manifest.

    Hope of help!