Jammer
Jammer

Reputation: 10206

Bot Framework Missing From.Id & Conversation.Id from Facebook Channels

I've raised a bug item against the C# Bot Builder project on GitHub but to be honest I can't really get to the bottom of whether this is a bug with the framework or a sporadic problem originating on the Facebook side.

We have been building the bot for a couple of months and have been using in development and staging exvironments extensively and have not seen this issue once.

So we go live with our first customer and boom. This issue starts occuring.

Value cannot be null. Parameter name: invalid activity-missing From.Id

And also:

Value cannot be null. Parameter name: invalid activity-missing Conversation.Id

The chats that produced this issue were started by users coming to the bot via the messenger web page and the Web Chat Plugin.

The users in both instances had used the "Get Started" button thus opting in to the chat. This opting in provides the bot with access to the users basic profile information.

Understandably this is pretty odd and I have been entirely unable to reproduce this issue in any testing in any of our environments (we have Dev, Staging and Live).

Has anyone else seen a similar issue?

What did you do to work around it?

At the moment since I cannot reproduce it anywhere I can't really close the bug or even have a vague level of confidence in it not happening again.

Upvotes: 4

Views: 534

Answers (1)

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

If your bot is designed with the Activity Handler, as demonstrated in the Samples-work-in-progress branch, you can add some code to the controller to log the entire Request.Body:

  [Route("api/messages")]
    [ApiController]
    public class BotController : ControllerBase
    {
        private readonly IBotFrameworkHttpAdapter Adapter;
        private readonly IBot Bot;

        public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
        {
            Adapter = adapter;
            Bot = bot;
        }

        [HttpPost]
        public async Task PostAsync()
        {
            Request.EnableBuffering();

            using (var buffer = new MemoryStream())
            {
                await Request.Body.CopyToAsync(buffer);
                buffer.Position = 0L;
                using (var bodyReader = new JsonTextReader(new StreamReader(buffer, Encoding.UTF8)))
                {
                    Debug.Print(BotMessageSerializer.Deserialize(bodyReader).ToString());
                    buffer.Position = 0L;
                }
            }

            Request.Body.Position = 0;

          await Adapter.ProcessAsync(Request, Response, Bot);
        }
    }

This should provide more information on what type of message is being sent to the bot. My guess is that it has something to do with a Facebook Messenger specific web hook you have subscribed to. For instance, I don't think 'message_echoes' are currently sent to the bot with a .From or conversation.Id. However, we have recently modified our Connector Service to include these: the release should be within the next few weeks.

Upvotes: 1

Related Questions