Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting a conversation with Microsoft bot builder and microsoft bot framework

I tried to have my bot start a conversation with the user but I don't know where in the code I should send the message from. The documentation for starting a convo is here, but it's not super helpful: http://docs.botframework.com/connector/new-conversations/#navtitle. I also tried replying in the HandleSystemMessages (which works with the emulator if I change the message type) but it still won't send the first message.

I'm using Microsoft Bot Connector and C#.

// Idk how to do syntax highlighting in stackoverflow // This is my code from the MessageController Class

public async Task<Message> Post([FromBody]Message message)
    {
        if (message.Type == "Message")
        {
            return message.CreateReplyMessage($"You said:{message.Text}");
        }
        else
        {
            return HandleSystemMessage(message);
        }
    }
like image 882
TheNappingKat Avatar asked Jun 11 '16 00:06

TheNappingKat


1 Answers

I spent a lot of time researching this issue. As a result, I managed to initiate sending a message on behalf of the bot. My example sends a message to a group conversation. The code below - is rough draft but it works:

class Program
{
    static void Main(string[] args)
    {
        var connector = new ConnectorClient(new Uri("https://skype.botframework.com"));
        var conversationId = "19:[email protected]";
        var conversation = new ConversationAccount(true, conversationId);
        var botAccount = new ChannelAccount("28:74a05skypeBotChannelAccountId", "your bot name");

        IMessageActivity message = Activity.CreateMessageActivity();
        message.From = botAccount;
        message.Conversation = conversation;
        message.ChannelId = "skype";
        message.Text = "some text";
        message.Locale = "en-En";
        connector.Conversations.SendToConversation((Activity)message);
    }
}
like image 180
Ruslan Borovok Avatar answered Nov 07 '22 13:11

Ruslan Borovok