Example #1
0
        private async Task <bool> ProcessFacebookPayload(ITurnContext turnContext, object data, CancellationToken cancellationToken)
        {
            try
            {
                var facebookPayload = (data as JObject)?.ToObject <FacebookPayload>();
                if (facebookPayload != null)
                {
                    // At this point we know we are on Facebook channel, and can consume the Facebook custom payload
                    // present in channelData.

                    turnContext.ApplyFacebookPayload(facebookPayload);

                    // Thread Control Request
                    if (facebookPayload.RequestThreadControl != null)
                    {
                        await OnFacebookThreadControlRequest(turnContext, facebookPayload, cancellationToken);

                        return(true);
                    }
                }
            }
            catch (JsonSerializationException)
            {
                if (turnContext.Activity.ChannelId != Channels.Facebook)
                {
                    await turnContext.SendActivityAsync("Primary Bot: This sample is intended to be used with a Facebook bot.");
                }
            }

            return(false);
        }