コード例 #1
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            Logger.LogInformation("Processing a Message Activity.");

            if (turnContext.Activity.Text?.Equals(EscalateOption, StringComparison.InvariantCultureIgnoreCase) == true)
            {
                await FacebookThreadControlHelper.RequestThreadControlToBot(turnContext, _configuration["SecondaryPageToken"], turnContext.Activity.From.Id, EscalateOption);
            }
            else if (turnContext.Activity.Text?.Equals(PrimaryBotOption, StringComparison.InvariantCultureIgnoreCase) == true)
            {
                await FacebookThreadControlHelper.PassThreadControlToPrimaryBot(turnContext, _configuration["PrimaryPageToken"], turnContext.Activity.From.Id, PrimaryBotOption);
            }
            else
            {
                // Show choices if the Facebook Payload from ChannelData is not handled
                if (!await ProcessFacebookPayload(turnContext, turnContext.Activity.ChannelData, cancellationToken))
                {
                    await ShowChoices(turnContext, cancellationToken);
                }
            }
        }
コード例 #2
0
        protected virtual async Task OnFacebookQuickReply(ITurnContext turnContext, FacebookQuickReply quickReply, CancellationToken cancellationToken)
        {
            Logger.LogInformation("QuickReply message received.");

            // TODO: Your quick reply event handling logic here...

            // Process the message by checking the Activity.Text.  The FacebookQuickReply could also contain a json payload.

            // Initially the bot offers to showcase 3 Facebook features: Quick replies, PostBack and getting the Facebook Page Name.
            switch (turnContext.Activity.Text)
            {
            // Here we showcase how to obtain the Facebook page id.
            // This can be useful for the Facebook multi-page support provided by the Bot Framework.
            // The Facebook page id from which the message comes from is in turnContext.Activity.Recipient.Id.
            case FacebookPageIdOption:
            {
                var reply = turnContext.Activity.CreateReply($"This message comes from the following Facebook Page: {turnContext.Activity.Recipient.Id} for the following Bot: {turnContext.Activity.Recipient.Name}");
                await turnContext.SendActivityAsync(reply, cancellationToken);
                await ShowChoices(turnContext, cancellationToken);

                break;
            }

            // Here we send a HeroCard with 2 options that will trigger a Facebook PostBack.
            case PostBackOption:
            {
                var card = new HeroCard
                {
                    Text    = "Is 42 the answer to the ultimate question of Life, the Universe, and Everything?",
                    Buttons = new List <CardAction>
                    {
                        new CardAction()
                        {
                            Title = "Yes", Type = ActionTypes.PostBack, Value = "Yes"
                        },
                        new CardAction()
                        {
                            Title = "No", Type = ActionTypes.PostBack, Value = "No"
                        },
                    },
                };

                var reply = turnContext.Activity.CreateReply();
                reply.Attachments = new List <Attachment> {
                    card.ToAttachment()
                };
                await turnContext.SendActivityAsync(reply, cancellationToken);

                break;
            }

            case EscalateOption:
            {
                await turnContext.SendActivityAsync("Requesting thread control for Secondary bot");

                await FacebookThreadControlHelper.RequestThreadControlToBot(turnContext, _configuration["SecondaryPageToken"], turnContext.Activity.From.Id, EscalateOption);

                break;
            }

            case PrimaryBotOption:
            {
                await turnContext.SendActivityAsync("Passing thread control to Primary bot");

                await FacebookThreadControlHelper.PassThreadControlToPrimaryBot(turnContext, _configuration["PrimaryPageToken"], turnContext.Activity.From.Id, PrimaryBotOption);

                break;
            }

            // By default we offer the users different actions that the bot supports, through quick replies.
            case QuickRepliesOption:
            default:
            {
                await ShowChoices(turnContext, cancellationToken);

                break;
            }
            }
        }