How to send message later in bot framework?

scheduled-tasks botframework

2055 просмотра

2 ответа

140 Репутация автора

I want my bot to be able to send some replies later. Like in alarm clock, when user says, ping me at 5 AM then I want to send message to the user at 5 AM. How can I send message without receiving one?

Автор: user2436032 Источник Размещён: 18.07.2016 10:45

Ответы (2)

4 плюса

540 Репутация автора


You'll need to receive at least one message so that you know the recipient's address. You'll need to save the addressing info from the incoming message. I think the easiest way is to save the whole message.


var reply = session.message; // address: reply.address
// ...
reply.text = 'Wake up!';


var reply = activity.CreateReply(""); // reply.Recipient, reply.Conversation, etc.
// ...
reply.Text = "Wake up!";
ConnectorClient connector = new ConnectorClient(new Uri(reply.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
Автор: Thegaram Размещён: 18.07.2016 05:06

0 плюса

10451 Репутация автора

Without reply to an activity request, you can send a message to him like the following. I should mention that you must have the user's Id, and it means at least the user should have sent a message to the bot, to store his id.

string userId ="123456789"; // For Example
string serviceUrl = ""; // For Example

var connector = new ConnectorClient(new Uri(serviceUrl));
IMessageActivity newMessage = Activity.CreateMessageActivity();
newMessage.Type = ActivityTypes.Message;
newMessage.From = new ChannelAccount("<BotId>", "<BotName>");
newMessage.Conversation = new ConversationAccount(false, userId);
newMessage.Recipient = new ChannelAccount(userId);
newMessage.Text = "<MessageText>";
await connector.Conversations.SendToConversationAsync((Activity)newMessage);

The above code comes from here.

Автор: OmG Размещён: 28.01.2017 07:15
Вопросы из категории :