2017-08-23 1 views
0

recordingStatusCallBackメソッドを使用してtwilioのメソッドを使用してコール録音にアクセスしたいのですが、recordingStatusCallBack私のaws apiゲートウェイと私のawsラムダでjsonを返すために私のAPIのゲートウェイ上のPOST要求を設定していませんでしたが、私はマシン上でnode.jsサーバーをセットアップし、ngrokを使ってトンネルして、 recordingStatusCallBack属性は正常に動作します。なぜ私のaws apiのゲートウェイで動作しませんでしたか?Twilio - recordStatusCallBackは、提供されたときにjsonデータを返さず、aws apiゲートウェイリンクとnode.jsサーバーがローカルで動作している場合

+0

試したコードを共有してください(エラーmsg、..)。理解しやすいように –

+0

@Nandhaそのコードではなく、単にrecordingStatusCallBackがjsonを返し、私のAPIゲートウェイでそのデータをlambdaに転送し、lambdaはtwilioのメソッドrecordingStatusCallBackによって送信されたjsonからなる完全な "イベント"オブジェクトを返します。私は誰もがそれを実装した場合にしたいですか? –

+0

ここで何が起こっているのか完全には分かっていませんが、Twilioは 'application/json'リクエストを送信しません。すべてのTwilioリクエストは 'application/x-www-form-urlencoded'として行われます。おそらく、フォームエンコードされたPOSTリクエストを受け取るためにAPIゲートウェイを微調整する必要がありますか? – philnash

答えて

0

私はapi-gatewayとtwilioで同じ問題がありました。あなたはのContent-Typeとしてを "アプリケーション/ x-www-form-urlencodedで" を追加し、あなたのテンプレートにこのコードを貼り付ける必要があり、APIゲートウェイでのごボディマッピング・テンプレート

## convert HTML POST data or HTTP GET query string to JSON 

## get the raw post data from the AWS built-in variable and give it a nicer name 
#if ($context.httpMethod == "POST") 
#set($rawAPIData = $input.path('$')) 
#elseif ($context.httpMethod == "GET") 
#set($rawAPIData = $input.params().querystring) 
#set($rawAPIData = $rawAPIData.toString()) 
#set($rawAPIDataLength = $rawAPIData.length() - 1) 
#set($rawAPIData = $rawAPIData.substring(1, $rawAPIDataLength)) 
#set($rawAPIData = $rawAPIData.replace(", ", "&")) 
#else 
#set($rawAPIData = "") 
#end 

## first we get the number of "&" in the string, this tells us if there is more than one key value pair 
#set($countAmpersands = $rawAPIData.length() - $rawAPIData.replace("&", "").length()) 

## if there are no "&" at all then we have only one key value pair. 
## we append an ampersand to the string so that we can tokenise it the same way as multiple kv pairs. 
## the "empty" kv pair to the right of the ampersand will be ignored anyway. 
#if ($countAmpersands == 0) 
#set($rawPostData = $rawAPIData + "&") 
#end 

## now we tokenise using the ampersand(s) 
#set($tokenisedAmpersand = $rawAPIData.split("&")) 

## we set up a variable to hold the valid key value pairs 
#set($tokenisedEquals = []) 

## now we set up a loop to find the valid key value pairs, which must contain only one "=" 
#foreach($kvPair in $tokenisedAmpersand) 
#set($countEquals = $kvPair.length() - $kvPair.replace("=", "").length()) 
#if ($countEquals == 1) 
    #set($kvTokenised = $kvPair.split("=")) 
    #if ($kvTokenised[0].length() > 0) 
    ## we found a valid key value pair. add it to the list. 
    #set($devNull = $tokenisedEquals.add($kvPair)) 
    #end 
#end 
#end 

## next we set up our loop inside the output structure "{" and "}" 
{ 
#foreach($kvPair in $tokenisedEquals) 
    ## finally we output the JSON for this pair and append a comma if this isn't the last pair 
    #set($kvTokenised = $kvPair.split("=")) 
"$util.urlDecode($kvTokenised[0])" : #if($kvTokenised.size() > 1 && $kvTokenised[1].length() > 0)"$util.urlDecode($kvTokenised[1])"#{else}""#end#if($foreach.hasNext),#end 
#end 
} 
関連する問題