dialogflow를 V2 API로 만들면 Webhook의 응답으로 문자 깨짐을 만난 이야기.

문제 개요



Dialogflow에서 V2 API가 공식이 되었기 때문에 V2 API로 전환하면 Webhook의 응답이 깨지게 되었습니다.



구성



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);





덧붙여 API Gateway의 설정으로 헤더에 추가해도 해결할 수 없어, 원인을 찾아내기까지 상당히 시간이 걸려 버렸다.

좋은 웹페이지 즐겨찾기