예제 #1
0
        protected override async Task OnEventActivityAsync(ITurnContext <IEventActivity> turnContext, CancellationToken cancellationToken)
        {
            if (turnContext.Activity.ChannelId == Channels.Directline && turnContext.Activity.Name == "RollResult")
            {
                var continueConversationActivity = (turnContext.Activity.Value as JObject)?.ToObject <Activity>();
                await turnContext.Adapter.ContinueConversationAsync(_botId, continueConversationActivity.GetConversationReference(), async (context, cancellation) =>
                {
                    logger.LogInformation(continueConversationActivity.Value as string);
                    var res          = RealDiceConverter.Deserialize <RollContext>(continueConversationActivity.Value as string);
                    var res0         = res.Results[0];
                    string exMessage = "";
                    if (res0.Status != "Success")
                    {
                        exMessage = $"({res0.Status})\n";
                    }
                    var message =
                        $"1d6 = {res0.Results[0]} !\n" +
                        $"(Score: {res0.Score})\n" +
                        exMessage +
                        $"> {continueConversationActivity.Text}";

                    var activity         = MessageFactory.Text(message);
                    activity.Attachments = GetAttachments(res0);

                    await context.SendActivityAsync(activity, cancellationToken);
                }, cancellationToken);
            }
            else
            {
                await base.OnEventActivityAsync(turnContext, cancellationToken);
            }
        }
예제 #2
0
        private static async Task SendResult(RollContext res)
        {
            var originalActivity = RealDiceConverter.Deserialize <Activity>(res.MetaData["RequestActivity"]);

            originalActivity.Value = RealDiceConverter.Serialize(res);
            var responseActivity = new Activity("event");

            responseActivity.Value = originalActivity;
            responseActivity.Name  = "RollResult";
            responseActivity.From  = new ChannelAccount("RealDiceFunctionsRollResult", "RealDiceFunctions");

            var directLineSecret = Environment.GetEnvironmentVariable("DirectLineSecret");

            using (DirectLineClient client = new DirectLineClient(directLineSecret))
            {
                var conversation = await client.Conversations.StartConversationAsync();

                await client.Conversations.PostActivityAsync(conversation.ConversationId, responseActivity);
            }
        }