0

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 (\"\").

6
  • Add response['hub.challenge'] = response['hub.challenge'].strip('"') before return statements in lambda
    – omuthu
    Commented Nov 19, 2022 at 12:11
  • 1
    @Rishabh Tyagi, even I am facing same issue, how did you resolve it? Commented Dec 4, 2022 at 5:50
  • 1
    We need to pass hub.challenge as a integer format instead of string. Whatsapp expecting integer format only. Commented Dec 4, 2022 at 6:53
  • @VenuJoginpally Yes you're right. I just converted it to an integer before returning it. Were you able to do the payload verfication where they ask you to verify "X-Signature" string? Commented Dec 6, 2022 at 18:50
  • which "X-signature" ? I didn't get you Commented Dec 7, 2022 at 13:07

1 Answer 1

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.