質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

0回答

640閲覧

Dialogflow のチュートリアルのFulfillmentの部分がうまくいきません

SasamiDaifuku

総合スコア6

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

2クリップ

投稿2018/04/25 16:33

編集2018/04/28 18:23

前提・実現したいこと

GoogleのDialogflowのチュートリアルをしているのですが、
Basic Fulfillment and Conversation Setup
のSetup Weather APIの章で詰まってしまったので質問します。

追記2018/04/29
因みにWeather APIはここから持ってきています(おそらく)
Weather API 入手先

発生している問題・エラーメッセージ

Setup Weather APIの章のチュートリアルの最後の部分で
weather
と入力したあとに
new york
と入力すると
new yorkの天気が出るとあるのですが、
Sorry I don't know the weather
が出てきてしまいます。
SHOW JSONの部分を見ると以下のように表示されます。
(responseID など固有の値は * に置き換えています)

{ "responseId": "*", "queryResult": { "queryText": "new york", "parameters": { "date": "", "geo-city": "New York" }, "allRequiredParamsPresent": true, "fulfillmentText": "Sorry I don't know the weather", "fulfillmentMessages": [ { "text": { "text": [ "Sorry I don't know the weather" ] } } ], "outputContexts": [ { "name": "*", "lifespanCount": 5, "parameters": { "geo-city": "New York", "date.original": "", "date": "", "geo-city.original": "new york" } } ], "intent": { "name": "*", "displayName": "weather" }, "intentDetectionConfidence": 1, "diagnosticInfo": { "webhook_latency_ms": 392 }, "languageCode": "en" }, "webhookStatus": { "code": 13, "message": "Webhook call failed. Error: 500 Internal Server Error" } }

Webhook call failed. Error: 500 Internal Server Errorがエラーメッセージぽいのですが、調べてもよくわかりませんでした。

該当のソースコード

ソースコードはチュートリアルにある通りのものをそのまま使用しています。

js

1// Copyright 2017, Google, Inc. 2// Licensed under the Apache License, Version 2.0 (the 'License'); 3// you may not use this file except in compliance with the License. 4// You may obtain a copy of the License at 5// 6// http://www.apache.org/licenses/LICENSE-2.0 7// 8// Unless required by applicable law or agreed to in writing, software 9// distributed under the License is distributed on an 'AS IS' BASIS, 10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11// See the License for the specific language governing permissions and 12// limitations under the License. 13 14'use strict'; 15const http = require('http'); 16const host = 'api.worldweatheronline.com'; 17const wwoApiKey = '*'; 18exports.weatherWebhook = (req, res) => { 19 // Get the city and date from the request 20 let city = req.body.result.parameters['geo-city']; // city is a required param 21 // Get the date for the weather forecast (if present) 22 let date = ''; 23 if (req.body.result.parameters['date']) { 24 date = req.body.result.parameters['date']; 25 console.log('Date: ' + date); 26 } 27 // Call the weather API 28 callWeatherApi(city, date).then((output) => { 29 // Return the results of the weather API to Dialogflow 30 res.setHeader('Content-Type', 'application/json'); 31 res.send(JSON.stringify({ 'speech': output, 'displayText': output })); 32 }).catch((error) => { 33 // If there is an error let the user know 34 res.setHeader('Content-Type', 'application/json'); 35 res.send(JSON.stringify({ 'speech': error, 'displayText': error })); 36 }); 37}; 38function callWeatherApi (city, date) { 39 return new Promise((resolve, reject) => { 40 // Create the path for the HTTP request to get the weather 41 let path = '/premium/v1/weather.ashx?format=json&num_of_days=1' + 42 '&q=' + encodeURIComponent(city) + '&key=' + wwoApiKey + '&date=' + date; 43 console.log('API Request: ' + host + path); 44 // Make the HTTP request to get the weather 45 http.get({host: host, path: path}, (res) => { 46 let body = ''; // var to store the response chunks 47 res.on('data', (d) => { body += d; }); // store each response chunk 48 res.on('end', () => { 49 // After all the data has been received parse the JSON for desired data 50 let response = JSON.parse(body); 51 let forecast = response['data']['weather'][0]; 52 let location = response['data']['request'][0]; 53 let conditions = response['data']['current_condition'][0]; 54 let currentConditions = conditions['weatherDesc'][0]['value']; 55 // Create response 56 let output = `Current conditions in the ${location['type']} 57 ${location['query']} are ${currentConditions} with a projected high of 58 ${forecast['maxtempC']}°C or ${forecast['maxtempF']}°F and a low of 59 ${forecast['mintempC']}°C or ${forecast['mintempF']}°F on 60 ${forecast['date']}.`; 61 // Resolve the promise with the output text 62 console.log(output); 63 resolve(output); 64 }); 65 res.on('error', (error) => { 66 reject(error); 67 }); 68 }); 69 }); 70}

試したこと

ここに問題に対して試したことを記載してください。
1つめ
res.send(JSON.stringify({ 'speech': error, 'displayText': error }));
の部分を
res.send(JSON.stringify({'fulfillmentText': response,}));
に変更

js

1// Copyright 2017, Google, Inc. 2// Licensed under the Apache License, Version 2.0 (the 'License'); 3// you may not use this file except in compliance with the License. 4// You may obtain a copy of the License at 5// 6// http://www.apache.org/licenses/LICENSE-2.0 7// 8// Unless required by applicable law or agreed to in writing, software 9// distributed under the License is distributed on an 'AS IS' BASIS, 10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11// See the License for the specific language governing permissions and 12// limitations under the License. 13 14'use strict'; 15const http = require('http'); 16const host = 'api.worldweatheronline.com'; 17const wwoApiKey = '*'; 18exports.weatherWebhook = (req, res) => { 19 // Get the city and date from the request 20 let city = req.body.result.parameters['geo-city']; // city is a required param 21 // Get the date for the weather forecast (if present) 22 let date = ''; 23 if (req.body.result.parameters['date']) { 24 date = req.body.result.parameters['date']; 25 console.log('Date: ' + date); 26 } 27 // Call the weather API 28 callWeatherApi(city, date).then((output) => { 29 // Return the results of the weather API to Dialogflow 30 res.setHeader('Content-Type', 'application/json'); 31 res.send(JSON.stringify({ 32 "fulfillmentText": response, 33 } 34 )); 35 }).catch((error) => { 36 // If there is an error let the user know 37 res.setHeader('Content-Type', 'application/json'); 38 res.send(JSON.stringify({ 39 "fulfillmentText": response, 40 } 41 )); 42 }); 43}; 44function callWeatherApi (city, date) { 45 return new Promise((resolve, reject) => { 46 // Create the path for the HTTP request to get the weather 47 let path = '/premium/v1/weather.ashx?format=json&num_of_days=1' + 48 '&q=' + encodeURIComponent(city) + '&key=' + wwoApiKey + '&date=' + date; 49 console.log('API Request: ' + host + path); 50 // Make the HTTP request to get the weather 51 http.get({host: host, path: path}, (res) => { 52 let body = ''; // var to store the response chunks 53 res.on('data', (d) => { body += d; }); // store each response chunk 54 res.on('end', () => { 55 // After all the data has been received parse the JSON for desired data 56 let response = JSON.parse(body); 57 let forecast = response['data']['weather'][0]; 58 let location = response['data']['request'][0]; 59 let conditions = response['data']['current_condition'][0]; 60 let currentConditions = conditions['weatherDesc'][0]['value']; 61 // Create response 62 let output = `Current conditions in the ${location['type']} 63 ${location['query']} are ${currentConditions} with a projected high of 64 ${forecast['maxtempC']}°C or ${forecast['maxtempF']}°F and a low of 65 ${forecast['mintempC']}°C or ${forecast['mintempF']}°F on 66 ${forecast['date']}.`; 67 // Resolve the promise with the output text 68 console.log(output); 69 resolve(output); 70 }); 71 res.on('error', (error) => { 72 reject(error); 73 }); 74 }); 75 }); 76}

結果→同じエラーが出る。

2つめ
GoogleCloudPlatformのバケットが
stanging.my-weather~

my-weather~
の二つあったので、
gcloud beta functions deploy weatherWebhook --stage-bucket [BUCKET_NAME] --trigger-http
の[BUCKET_NAME]をそれぞれに変更してコンパイルを行う。

結果→同じエラーが出る

以上です。
考えても検索しても糸口がつかめなかったので、
もしわかる方や、チュートリアルをこうしたらできたよという方がいましたら教えていただきたいです。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問