When I am trying to configure meta webhook using AWS API as callback URL for my lambda function, I am getting an error: The URL couldn't be validated. Response does not match challenge, expected value="802376652", received="null"
Here is my lambda function code:
app_secret = os.environ['APP_SECRET']
verify_token = os.environ['VERIFY_TOKEN']
app_token = os.environ['APP_TOKEN']
def lambda_handler(event, context):
if "httpMethod" in event and event["httpMethod"] == "GET":
query_params = event.get("queryStringParameters", {})
mode = query_params.get("hub.mode")
token = query_params.get("hub.verify_token")
challenge = query_params.get("hub.challenge")
if mode and token and mode == "subscribe" and token == verify_token:
return {
"statusCode": 200,
"body": challenge
}
else:
return {
"statusCode": 403
}
elif "httpMethod" in event and event["httpMethod"] == "POST":
body = json.loads(event["body"])
if "object" in body and body["object"] == "page":
for entry in body.get("entry", []):
if "messaging" in entry:
for messaging_event in entry["messaging"]:
if "message" in messaging_event:
sender_id = messaging_event["sender"]["id"]
userText = messaging_event["message"]["text"]
handle_message(sender_id, userText)
return {"statusCode": 200}
else:
return {"statusCode": 400}
def verify_signature(request_payload, signature_header):
signature = hmac.new(app_secret.encode(), request_payload, hashlib.sha1).hexdigest()
return signature == signature_header.split('=')[1]
def handle_message(sender_id, userText):
#MyfurtherCodes
Kindly check and suggest any solution that why I am not able to configure my AWS API as callback URL in meta webhook.
Note: (1). I haven't used any auth in AWS API, just set environmental variables as I have mentioned in lambda function code. (2). I used python language for writing my lambda function code.