0

So I've been following this guide on how to send proactive messages, I've got that setup but it currently responds to the setup message. I would like it to create a whole new conversation, I've found some code that uses the CreateConversationAsync() function but I've only managed to get it to work with it dm-ing the user rather than within the channel. See below for code example.

I know I'm doing something wrong but I can't tell what at this point.

const string botAppId = "<MicrosoftApptId GUID>";
const string serviceUrl = "<my service URL>";
const string tenantId = "<my tenant ID>";
const string recipientId = "<recipient ID xy:GUID>";

var title = "test title";
var activity = Activity.CreateMessageActivity();
activity.Type = ActivityTypes.Message;
activity.Text = "test message";

await ((BotAdapter)_adapter).CreateConversationAsync(
    botAppId: botAppId,
    channelId: Microsoft.Bot.Connector.Channels.Msteams,
    serviceUrl: serviceUrl,
    audience: null,
    conversationParameters: new ConversationParameters
    {
        Activity = (Activity)activity,
        Bot = new ChannelAccount(botAppId),
        IsGroup = false,
        Members = new List<ChannelAccount> { new ChannelAccount(recipientId) },
        TopicName = title,
        TenantId = tenantId
    },
        callback: BotCallback,
        cancellationToken: default(CancellationToken));

1 Answers1

0

You're using "recipient id", which is presumably something unique for that user, like the user's unique Azure AD ID, that might be why it's 'DM'ing' the user, so to speak. What you need to do is capture the 'conversationId' of the conversation the bot was added to, which is basically the conversationId for the channel.

Here's a more detailed answer I gave on this topic, together with links to a sample and a video covering proactive messaging, which should hopefully be useful in solving this: Sending proactive messages from an outside process to organizational users via Teams chat bot

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24