我的设置是一个从 API Gateway 接收 POST 数据的 AWS Lambda 函数。当我向我的 Twilio 号码发送 WhatsApp 消息时,Webhook 是从 Twilio 发送的。
有人可以向我解释这里发生了什么吗?有没有办法避免冒号转换为%3A%2B
. 或者这是我必须在更深层次上对 Pyhton 做的事情?
AWS API Gateway,集成请求 - 映射模板
#set($httpPost = $input.path('$').split("&"))
{
#foreach( $kvPair in $httpPost )
#set($kvTokenised = $kvPair.split("="))
#if( $kvTokenised.size() > 1 )
"$kvTokenised[0]" : "$kvTokenised[1]"#if( $foreach.hasNext ),#end
#else
"$kvTokenised[0]" : ""#if( $foreach.hasNext ),#end
#end
#end
}
AWS Lambda 函数
def lambda_handler(event, context):
print("Received event: " + str(event))
print("Received Body: " + str(event.get('Body')))
return 200
# return '<?xml version=\"1.0\" encoding=\"UTF-8\"?>'\
# '<Response><Message>Hello world! -Lambda</Message></Response>'
在我的控制台中打印。whatsapp%3A%2B491573599343
应该whatsapp:491573599343
Received event: {'SmsMessageSid': 'SM851aa11c912d3775d7941143d8b935f9', 'NumMedia': '0', 'SmsSid': 'SM851aa11c912d3775d7941143d8b935f9', 'SmsStatus': 'received', 'Body': 'Hi', 'To': 'whatsapp%3A%2B4915735992273', 'NumSegments': '1', 'MessageSid': 'SM851aa11c912d3775d7941143d8b935f9', 'AccountSid': 'AC358aa1d18557365a9e1f5e2ffcbcebe0', 'From': 'whatsapp%3A%2B49160343202', 'ApiVersion': '2010-04-01'}
更新:
#set($httpPost = $input.path('$').split("&"))
{
#foreach( $kvPair in $httpPost )
#set($kvTokenised = $kvPair.split("="))
#if( $kvTokenised.size() > 1 )
"$kvTokenised[0]" : "$esc.unurl($kvTokenised[1])"#if( $foreach.hasNext ),#end
#else
"$kvTokenised[0]" : ""#if( $foreach.hasNext ),#end
#end
#end
}