以下は私がjsonファイルを解析し、それを印刷するために "for"アウトコンソール「forループ」を使用して、「googleによる処理」の解析済みjsonファイルを使用してリストを構築するときの問題
process.env.DEBUG = 'actions-on-google:*';
const apikey = "xxxxxx";
const https = require('https');
const ActionsSdkApp = require("actions-on-google");
const DialogflowApp = require('actions-on-google').DialogflowApp;
const app = new ActionsSdkApp({request, response});
//ActionsSdkApp({request, response} vs DialogflowApp({ request: req, response: res })?????? which one do I use????
function responseHandler(app) {
var topic = app.getArgument('topic');
https.get(`https://example.com/${topic}?apiKey=${apikey}`, (res) => {
let body = "";
res.on('data', data => {
console.log('Reading Data');
body += data.toString();
});
res.on('end',() => {
try {
const profile = JSON.parse(body);
for(let i = 0; i<profile.data.length;i++) {
console.log(" description: " + profile.data[i].description + " title: " + profile.data[i].title +); // in the json file there are vales called "description" and "title" that I want on my list
}} catch (e) {
app.ask("Sorry, I was unable to load information. Please repeat the search term.");
console.error("error: " + e.message);
}
});
})
}
に私はactions by google documentation上の例を次のようだし、私は私のJSONファイル内のすべてのJSONオブジェクトのリストを作成しようとしていますが、私は困難を抱えています。以下は私の試みです:
function list() {
const app = new ActionsSdkApp({request, response});
app.askWithList('Here are a few things I found. Pick one that looks interesting',
app.buildList('Things to learn about')
// i want add my loop here....but I how would I add it probably?? for(let i = 0; i<profile.data.length;i++)
.addItems
.setTitle(" title: " + profile.data[i].title)
.setDescription(" description: " + profile.data[i].description)
);
};
リストの作成に役立つアドバイスはありますか?また、actionsdkライブラリまたはdialogflowライブラリをインポートしますか?
こんにちは、私は最近このプロジェクトに戻り、私は困惑しています。私はユーザーのクエリに基づいて研究記事のリストを取得するGoogleのアシスタントアプリケーションを作ることを望んでいる。たとえば、ユーザーが「バッテリー技術」で記事を読んでみたい場合、アプリはカードのリストを表示し、各カードカードにはタイトルと記事へのURLリンクがあります。私の質問は、 "エイリアス"変数が本当に必要かどうかです。 "キー"変数はユーザーが要求する検索語で、最後にユーザーがカードをクリックすると、URLは自動的に記事に開きます。 –
これは明らかではありませんが、まったく異なる質問をしているようです。もしそうなら、新しいStackOverflow質問としてそれを聞いてください。これが答えなかったために元の質問を明確にしようとしているなら、それを更新してください。これがあなたの質問に答えるなら(それはループで応答を構築することでした)、答えを受け入れるか、アップアップするかは常に高く評価されます。 – Prisoner
十分なバックグラウンドを与えないと申し訳ありません。私は新しい投稿をhttps://stackoverflow.com/questions/48402373/building-a-list-in-actions-on-googleに投稿しました。私はupvoteを与えましたが、私は十分な担当者がいないために表示されません。ポイント –