Send and receive text message

APPLIES TO: yesSDK v4 no SDK v3

The primary way your bot will communicate with users, and likewise receive communication, is through message activities. Some messages may simply consist of plain text, while others may contain richer content such as cards or attachments. Your bot's turn handler receives messages from the user, and you can send responses to the user from there. The turn context object provides methods for sending messages back to the user. This article describes how to send simple text messages.

Markdown is supported for most text fields, but support may vary by channel.

For a running bot sending and receiving messages, follow the quickstarts at the top of the table of contents or check out the article on how bots work, which also links to simple samples available for you to run yourself.

Send a text message

To send a simple text message, specify the string you want to send as the activity:

In the bot's activity handlers, use the turn context object's SendActivityAsync method to send a single message response. You can also use the object's SendActivitiesAsync method to send multiple responses at once.

await turnContext.SendActivityAsync($"Welcome!");

Receive a text message

To receive a simple text message, use the text property of the activity object.

In the bot's activity handlers, use the following code to receive a message.

var responseMessage = turnContext.Activity.Text;

Additional resources

Next steps