LoginSignup
11
7

More than 5 years have passed since last update.

dialogflowをV2 APIにしたらWebhookのレスポンスで文字化けに遭遇した話。

Last updated at Posted at 2018-05-27

問題概要

DialogflowでV2 APIが公式になったということでV2 APIに切り替えたら、Webhookからのレスポンスが文字化けするようになりました。

mojibake.png

構成

Google Assistant → Dialogflow → AWS API Gateway → AWS Lambda

解決

Lambdaで設定するレスポンスのヘッダに"charset=UTF8"を追加したら解決した。1

Lambdaのindex.js(before)
    var response_json = {
        fulfillmentText:"こんにちは"
    };
    var response = {
        statusCode: 200,
        headers: { "Content-type": "application/json" },
        body: JSON.stringify(response_json)
    };
    context.succeed(response);
Lambdaのindex.js(after)
    var response_json = {
        fulfillmentText:"こんにちは"
    };
    var response = {
        statusCode: 200,
        headers: { "Content-type": "application/json; charset=UTF-8" },
        body: JSON.stringify(response_json)
    };
    context.succeed(response);

mojibaketenai.png


  1. なお、API Gatewayの設定でヘッダに追加してみても解決できず、原因を見つけるまでに随分時間がかかってしまった。 

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7