1

My goal is to receive WhatsApp messages via API Gateway and store these in DynamoDB. I receive the data the following way through my webhook. My problem is that when Body should be saved as "Hello world" into the database. It is saved as "Hello+World". Do you have any idea how to avoid that behavior?

{'SmsMessageSid': 'SMb980630d616e300921cacc5d27835fb1', 'NumMedia': '0', 'SmsSid': 'SMb980630d616e300921cacc5d27835fb1', 'SmsStatus': 'received', 'Body': 'Test+131415+5%2B5%3D10', 'To': 'whatsapp%3A%2B4915734392273', 'NumSegments': '1', 'MessageSid': 'SMb980630d616e300921cacc5d27835fb1', 'AccountSid': 'AC358aa1d18557365a9e1f5e2ffcbcebe0', 'From': 'whatsapp%3A%2B4942357902', 'ApiVersion': '2010-04-01'}

When I print the received webhook, I already see Body formated the "wrong" way. I tried the following

messageBody = event.get('Body')
messageBody = unquote(messageBody)

But this only solved the part that %2B and %3D were now shown as

Test+131415+5+5=10

However, the + Between Test 131415 are still there.

I have the following Mapping Template in my API Gateway Integration Request (found here):

#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
}
Joey Coder
  • 3,199
  • 8
  • 28
  • 60

1 Answers1

0

Here the solution: urllib.parse.unquote_plus

Joey Coder
  • 3,199
  • 8
  • 28
  • 60