コード例 #1
0
        private async Task PostNewQuestion(IDialogContext context)
        {
            try
            {
                string conversationId = context.MakeMessage().Conversation.Id;

                byte level = context.ConversationData.GetValueOrDefault <byte>(KEY_LEVEL);

                Trace.TraceInformation($"PostNewQuestion: conversation: {conversationId}; level: {level}");

                QuestionItem newQuestion = await _questionData.GetRandomQuestion(conversationId, (QuestionComplexity)level);

                Trace.TraceInformation($"PostNewQuestion: {newQuestion.Id}, {newQuestion.Question}, {newQuestion.Answer}");

                if (newQuestion != null)
                {
                    newQuestion.InitUrls("https://db.chgk.info/images/db/");

                    context.ConversationData.SetValue(KEY, newQuestion);

                    IMessageActivity message = context.MakeMessage();

                    message.Id = newQuestion.Id.ToString();

                    CardAction answerAction = new CardAction()
                    {
                        Title = "Answer",
                        Type  = "imBack",
                        Value = "answer"
                    };

                    message.Text = $"**Question:**<br/>{newQuestion.Question}<br/><br/>" +
                                   $"**Author:** {newQuestion.Authors ?? "Unknkown"}<br/>" +
                                   $"**Tour:** {newQuestion.TournamentTitle ?? "Unknkown"}";

                    message.Attachments      = newQuestion.QuestionImageUrls.Select(ToAttachement).ToList();
                    message.SuggestedActions = new SuggestedActions
                    {
                        Actions = new List <CardAction> {
                            answerAction
                        }
                    };

                    await context.PostAsync(message);
                }
                else
                {
                    await context.SayAsync("I'm sorry there are no more questions for you. Please, try to set another level :-(");
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Exception in PostNewQuestion", ex);
                await context.SayAsync("I'm sorry - something wrong has happened.");
            }
        }
コード例 #2
0
ファイル: RootDialog.cs プロジェクト: koljada/WhatWhereWhen
        public async static Task <IMessageActivity> PostNewQuestion(IBotDataBag conversationData, IMessageActivity messageActivity)
        {
            string conversationId = messageActivity.Conversation.Id;

            byte level = conversationData.GetValueOrDefault <byte>(KEY_LEVEL);

            Trace.TraceInformation($"PostNewQuestion: conversation: {conversationId}; level: {level}");

            QuestionItem newQuestion = await new QuestionDataSql().GetRandomQuestion(conversationId, (QuestionComplexity)level);

            Trace.TraceInformation($"PostNewQuestion: {newQuestion?.Id}, {newQuestion?.Question}, {newQuestion?.Answer}");

            if (newQuestion != null)
            {
                newQuestion.InitUrls("https://db.chgk.info/images/db/");

                conversationData.SetValue(KEY, newQuestion);

                messageActivity.Id = newQuestion.Id.ToString();

                CardAction answerAction = new CardAction()
                {
                    Title = "Answer",
                    Type  = "imBack",
                    Value = "answer"
                };

                messageActivity.Text = $"**Question:**<br/>{newQuestion.Question}<br/><br/>" +
                                       $"**Author:** {newQuestion.Authors ?? "Unknkown"}<br/>" +
                                       $"**Tour:** {newQuestion.TournamentTitle ?? "Unknkown"}";

                messageActivity.Attachments      = newQuestion.QuestionImageUrls.Select(ToAttachement).ToList();
                messageActivity.SuggestedActions = new SuggestedActions
                {
                    Actions = new List <CardAction> {
                        answerAction
                    }
                };

                return(messageActivity);
            }

            return(null);
        }