1
votes

I am using bot framework to have a chat bot. I use it in Microsoft Teams.

I want to send a message from user to bot programetically. But i am not able to do that.

I tried using direct line but it didnt help me. I am new to this bot framework.

var directLineSecret = "directlinesecretkey";
var client = new DirectLineClient(directLineSecret);
var conversation = await client.Conversations.StartConversationAsync();

var testActivity = new Activity
{
    From = new Microsoft.Bot.Connector.DirectLine.ChannelAccount(objectid, userName),
    Type = Microsoft.Bot.Connector.DirectLine.ActivityTypes.Message,
    Text = "Hello from the PCE!"
};

var response = await client.Conversations.PostActivityAsync(conversation.ConversationId, testActivity);

Activity userMessage = new Activity
{
    From = new Microsoft.Bot.Connector.DirectLine.ChannelAccount(objectid, userName),
    Text = "test",
    Type = Microsoft.Bot.Schema.ActivityTypes.Message
};

await client.Conversations.PostActivityAsync(conversation.ConversationId, testActivity);
await client.Conversations.PostActivityAsync(conversation.ConversationId, userMessage);

Please help me with this. While executing this code i am getting response in var response but the message is not sent nor i see the log in the bot framework.

1
Can anyone help me on this?user10754742
"I want to send a message from user to bot programetically" are your sure you are trying to do send a message in that way? Looking at the code you provided, it looks like you want to send from bot to userNicolas R
Hi @NicolasR I am not sure on how to do this i am very much new to this. But yes i want to send the message from user to bot programetically. I saw something called imback but that doesnt work with adaptive cards. I need it to be used with adaptive cardsuser10754742
@NicolasR any idea on how to work on this?user10754742
@KyleDelaney yes that is what i am trying to can you help me with the codeuser10754742

1 Answers

0
votes

An Adaptive Card can simulate an imBack with an adaptive submit action under two conditions:

  1. The adaptive card must have no input elements
  2. The action's Data property must be a string (the text to be sent from the user)

Here's a example of how you might create and send such a card in BotBuilder v4 using the AdaptiveCards NuGet package:

var card = new AdaptiveCard
{
    Body = { new AdaptiveTextBlock("Adaptive Card") },
    Actions = { new AdaptiveSubmitAction { Title = "Say 'test'", Data = "test" } },
};

var reply = (Activity)MessageFactory.Attachment(new Attachment {
    ContentType = AdaptiveCard.ContentType,
    Content = card,
});

await turnContext.SendActivityAsync(reply);