protected virtual async Task OnFacebookThreadControlRequest(ITurnContext turnContext, FacebookPayload facebookPayload, CancellationToken cancellationToken) { _logger.LogInformation("PrimaryBot - Thread Control Request message received."); string requestedOwnerAppId = facebookPayload.RequestThreadControl.RequestedOwnerAppId; if (facebookPayload.RequestThreadControl.Metadata == "please") { await turnContext.SendActivityAsync($"Primary Bot: {requestedOwnerAppId} requested thread control nicely. Passing thread control..."); var success = await FacebookThreadControlHelper.PassThreadControlAsync( _configuration["FacebookPageToken"], requestedOwnerAppId, facebookPayload.Sender.Id, "allowing thread control"); if (!success) { // Account for situations when the primary receiver doesn't have thread control await turnContext.SendActivityAsync("Primary Bot: Thread control could not be passed."); } } else { await turnContext.SendActivityAsync($"Primary Bot: {requestedOwnerAppId} requested thread control but did not ask nicely." + " Thread control will not be passed." + " Send any message to continue."); } }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { var text = turnContext.Activity.Text; switch (text) { case OPTION_PASS_PAGE_INBOX: await turnContext.SendActivityAsync("Primary Bot: Passing thread control to the page inbox..."); await FacebookThreadControlHelper.PassThreadControlAsync(_configuration["FacebookPageToken"], PAGE_INBOX_ID, turnContext.Activity.From.Id, text); break; case OPTION_PASS_SECONDARY_BOT: var secondaryReceivers = await FacebookThreadControlHelper.GetSecondaryReceiversAsync(_configuration["FacebookPageToken"]); foreach (var receiver in secondaryReceivers) { if (receiver != PAGE_INBOX_ID) { await turnContext.SendActivityAsync($"Primary Bot: Passing thread control to {receiver}..."); await FacebookThreadControlHelper.PassThreadControlAsync(_configuration["FacebookPageToken"], receiver, turnContext.Activity.From.Id, text); break; } } break; case OPTION_REQUEST_THREAD_CONTROL: case OPTION_REQUEST_THREAD_CONTROL_NICELY: // Do nothing because the secondary receiver should react to these instead break; default: await ShowChoices(turnContext, cancellationToken); break; } }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { var text = turnContext.Activity.Text; switch (text) { case OPTION_PASS_PRIMARY_BOT: await turnContext.SendActivityAsync("Secondary Bot: Passing thread control to the primary receiver..."); // A null target app ID will automatically pass control to the primary receiver await FacebookThreadControlHelper.PassThreadControlAsync(_configuration["FacebookPageToken"], null, turnContext.Activity.From.Id, text); break; case OPTION_TAKE_THREAD_CONTROL: // Do nothing because the primary receiver should react to this instead break; default: await ShowChoices(turnContext, cancellationToken); break; } }