0

I'm currently trying to send a proactive message with my Microsoft Teams bot by using the following example code that I see online:

var address =
{
    channelId: 'msteams',
    user: { id: userId },
    channelData: {
        tenant: {
            id: tenantId
        }
    },
    bot:
    {
        id: appId,
        name: appName
    },
    serviceUrl: session.message.address.serviceUrl,
    useAuth: true
}

var msg = new builder.Message().address(address);
msg.text('Hello, this is a notification');
bot.send(msg);

The only change made is that I use TeamsMessage instead of a regular Message because I get errors saying that Message isn't a class which has also confused me. The problem when I run the code is that it tells me that my bot doesn't have a function named 'send'. My bot extends the TeamsActivityHandler class. My question is how do I fix this issue?

  • 1
    You don't seem to have a conversation reference. Messages can't be sent by bots without the user first interacting with the bot giving you a conversation reference. Installing the application into teams will give you this initial reference. Try and follow this example https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/16.proactive-messages – Adam James Mar 29 '20 at 21:22

1 Answers1

0

You need the user’s unique ID and tenant ID to send a proactive message. Typically, these are obtained from a team context, either by fetching the team roster or when a user interacts with your bot in a channel. Please check documentation on how to send proactive message.

Here is the source code for Node.js sample for Proactive Messages.

Subhasish
  • 504
  • 2
  • 9
  • I've been able to acquire both ID's for the message. The problem is I don't know how to send the information. When I try 'bot.send' it says that the 'send' method doesn't exist and I've seen examples use 'session.send' but I don't know how to get the session object. – cbrandsdev12 Mar 30 '20 at 13:50
  • Is it just a new Session object I create? – cbrandsdev12 Mar 30 '20 at 13:56
  • Can you please provide more context on the shared code? like what instance is "bot" ans also Can you please share which document you are referring? – Subhasish Mar 30 '20 at 16:01
  • The example using a session is the link you sent me which is [here](https://github.com/OfficeDev/microsoft-teams-sample-complete-node/blob/master/src/dialogs/examples/teams/ProactiveMsgTo1to1Dialog.ts). The bot itself is a class that extends the TeamsActivityHandler class in the bot sdk (v4). What I'm attempting to do is given only a user ID from the team, personally message that ID when an event happens. – cbrandsdev12 Mar 30 '20 at 16:14
  • I can get the tenant ID and User ID but the problem is I don't know how to send a message to that user's address in version 4 of the botbuilder module. – cbrandsdev12 Mar 30 '20 at 16:23
  • I'm trying to send a proactive message without having any previous conversation reference. – cbrandsdev12 Mar 30 '20 at 18:25
  • 1
    I found the solution to my issue [here](https://stackoverflow.com/questions/57496329/proactive-messaging-bot-in-teams-without-mentioning-the-bot-beforehand/57499608#57499608) – cbrandsdev12 Mar 31 '20 at 18:30