Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c# BotBuilder V3 | CreateDirectConversationAsync not working, SendToConversationAsync is working #959

Closed
JPThorne opened this issue Aug 10, 2016 · 1 comment
Assignees

Comments

@JPThorne
Copy link

JPThorne commented Aug 10, 2016

Hi there.

So I'm trying to send a message from the Bot to the User. Have followed the guidelines as layed out here: https://docs.botframework.com/en-us/csharp/builder/sdkreference/routing.html specifically, the Create 1:1 Conversations section. The sample code does work, however, it only works when I substitute the original conversationId received from the emulator for the conversationId created by CreateDirectConversationAsync. So it seems CreateDirectConversationAsync is not generating a useful conversationId?

Here is my code:

//hardcoded values retrieved from the emulator - inspecting an incoming message.
var botAccount = new ChannelAccount("56800324", "Bot1");
var userAccount = new ChannelAccount(name: "User1", id: "2c1c7fa3");

var connector = new ConnectorClient(new Uri("http://localhost:9000/"));
//var conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);
IMessageActivity message = Activity.CreateMessageActivity();
message.From = botAccount;
message.Recipient = userAccount;

//this is the orignal conversationId as the emulator sent. 
//Using it works - the message is received in the emulator. 
//Using conversationId.Id does not work - No message is received in the emulator
var hardcodedId = "8a684db8"; 

message.Conversation = new ConversationAccount(id: hardcodedId, name: "Conv1", isGroup: false);
message.Text = "Hi there";

await connector.Conversations.SendToConversationAsync((Activity)message);

Any feedback would be much appreciated. I have seen similar issues here: #698 but that sample code suggestion also does not work.

@msft-shahins
Copy link
Contributor

The code snippet below produces the following results in emulator and the CreateDirectConversation(...) works. Make sure to look for the direct conversation showing up as Bot1-User1 from conversation names drop down in emulator.

                        var botAccount = new ChannelAccount("56800324", "Bot1");
                        var userAccount = new ChannelAccount(name: "User1", id: "2c1c7fa3");

                        var connector = new ConnectorClient(new System.Uri(activity.ServiceUrl));
                        var conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);
                        var message = Activity.CreateMessageActivity();
                        message.From = botAccount;
                        message.Recipient = userAccount;
                        message.Conversation = new ConversationAccount(id: conversationId.Id, isGroup: false);
                        message.Text = "Hi there";
                        await connector.Conversations.SendToConversationAsync((Activity)message);

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants