0
votes

I'm trying to get a v4 bot framework bot (C# SDK) to initiate a 1:1 conversation with a user, and I need to be able to get/create the conversation ID. I'm calling this:

var response = await m_client.Conversations.CreateDirectConversationAsync(new ChannelAccount(aadObjectId: "DB84C737-2161-4A35-B8C3-274B1FA4CF15", role: "bot"),
    new ChannelAccount(role:"user",aadObjectId:"045AD4DB-133B-4C1B-870B-8201B7233625"));

// Construct the message to post to conversation
Activity newActivity = new Activity()
{
    Text = "Hello",
    Type = ActivityTypes.Message,
    Conversation = new ConversationAccount
    {
        Id = response.Id
    },
};

// Post the message to chat conversation with user
await m_client.Conversations.SendToConversationAsync(newActivity);

Which is coming back as a bad request. If I have a user message my bot first (or look for the ConversationUpdated event when they add the bot), I can save the conversation ID (something like a:1NJglnU1nkB-rqiCw2pQjbwMVViEYxyGxqGr8roBJMwtzzyDt_usg02D4HyaACgen_dOkikceYF3vdQ6kt6UAlxcT-tgCw7H8RWw46lLHBKYpxhkzgmMYJ9kOxiseAZga), but I want to be able to retrieve/generate that for a user without them having to message the bot first, which is what I thought CreateDirectConversationAsync would give me.

I've also tried setting the ID parameters for the user/bot (address@domain) as well as the aad object IDs, but the result is the same. Is there a way that I can have my bot create a conversation ID for a 1:1 chat from the SDK?

1

1 Answers

0
votes

It's been a while since I played with it, and that was when there was still a Microsoft.Bot.Connector.Teams package, but that's rolled into the core bot framework now. As a result, I think you'd now look to use:

m_client.Conversations.CreateConversationAsync

instead of

m_client.Conversations.CreateDirectConversationAsync

On that overload, the key thing is to set the correct values on the "ConversationParameters" object, especially the "Bot", "Members" and "TenantId" properties.