Home > Mobile >  Is there a way to decode the string returned from AWS lambda to meta's whatsapp business api?
Is there a way to decode the string returned from AWS lambda to meta's whatsapp business api?

Time:12-07

I am trying to setup a webhook in AWS Lambda (using API Gateway) for Meta's WhatsApp Business API. They have the following guidelines:

Whenever your endpoint receives a verification request, it must:

Verify that the hub.verify_token value matches the string you set in the Verify Token field when you configure Webhooks in your App Dashboard (you haven't set up this token string yet). Respond with the hub.challenge value."

I have setup all the query strings it needs in the API gateway. Here is what my lambda handler looks like:

def lambda_handler(event, context):
    response = {
        "status": 400,
        "body" : "failed"
    }
    
    print(str(event))
    
    print("Received context"   str(context))
    
    if(len(event) != 0 and (event['hub.verify_token'] == "some value")):
        response['status'] = 200
        response['body'] = event['hub.challenge']
        return event['hub.challenge']
     
        #print(response)
        #returnResponse = re.findall('[0-9] ', event['hub.challenge'])
        #return returnResponse[0]
        
    else:
        return(response)

the event looks like:

{
    "hub.mode" : "some value",
    "hub.verify_token": "some value",
    "hub.challenge": "1158201444"
}

The response in AWS console looks like "1158201444" but on meta's end, the response looks like "\"1158201444\"" and the webhook confirmation fails in Meta's dashboard.

How can remove the extra characters and decode the string? I have already tried regex and still getting the extra characters (\"\").

CodePudding user response:

So what worked for me is was that I passed hub.challenge as a integer format instead of string. I just converted it to an integer before returning it.

  • Related