1
votes

I am looking for equivalent for CreateReply method in SDK v4 Same as explained in below article: https://docs.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-connector?view=azure-bot-service-3.0

How I can Send a (non-reply) message? Thanks

2

2 Answers

2
votes

As for your question "How I can Send a (non-reply) message?":

It's there in the link you provided (section Start a conversation).
You can create one manually using Activity.CreateMessageActivity() for example. You'll have to set all values manually and have an instantiated connector for it to work.

If you want to send an activity during a bot turn where you have the user's activity, you can use that activity object to populate a lot of the fields.

On the other hand, if you want to send activities to users from an outside trigger, you'll have a bit more work.

You can check this sample about proactive messages in BotBuilder-Samples: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/16.proactive-messages

Here they inject a ConcurrentDictionary as singleton to be shared by a controller and the bot.
The bot adds entries to this dictionary when users interact with it (see AddConversationReference).
The controller iterates the entries and sends the same activity to all users who previously talked with the bot in the BotCallback method.

It's not a production-ready implementation as a simple restart makes the app forget all users, but it gives you an idea of what needs to be maintained in order to send proactive messages to users.

You can read Microsoft's article about this

0
votes

I got it working in the Main Dialog (OnMessageActivityAsync) by doing this. See my full answer here.

var reply = (turnContext.Activity as Activity).CreateReply();
                                reply.Type = ActivityTypes.Message;
                                reply.Text = "Does this work for you?
                                reply.ChannelData = JObject.FromObject(new 
                                {
                                    recipient,
                                    message
                                });

await turnContext.SendActivityAsync(reply, cancellationToken);