Search code examples
node.jsfacebook-messengerazure-functions

NodeJS Azure Functions used as a Messenger Bot return an mscorlib error


I'm trying to use Azure Functions as a Messenger bot server using a Generic Webhook. The problem I'm running into is that even running this simple code (most of it is commented out to try & figure out the issue) results in an error (below the code):

module.exports = function (context, data) {
    context.log('Webhook was triggered!');

            context.res = {
                status: 403,
                body: ''
            }

    context.done();
}

Function completed (Failure, Id=fb0f2178-8b98-4163-a5ae-7ab68eff47cd) Exception while executing function: Functions.StriverMessenger. mscorlib: The given key was not present in the dictionary.

Why is this error occurring and how do I get this to work? If I fake out the querystring entries in the run mode inside Azure, the function appears to work as coded. The error occurs when trying to send a Verify request to the Azure Function from Facebook Developer, specifically in Messenger's Webhook setup.


Solution

  • This happens when an empty (or non-json) body is sent to a Function with type WebHook. The handling is poor, and we are improving it per https://github.com/Azure/azure-webjobs-sdk-script/issues/849. This should be deployed within a week and you can then verify.