簡體   English   中英

通過Google Actions / Dialogflow訪問API

[英]Access an API through Google Actions/Dialogflow

我想通過Jenkins API觸發Jenkins作業,我們可以通過點擊類似於“ JENKINS_URL / job / JOBNAME / build”的URL來完成該任務。

我想通過Google action / Dialogflow來訪問API。

有沒有可用的教程來完成我想要實現的類似過程?

您應該看一下Dialogflow報價示例,該示例顯示了如何進行外部API調用:

// Retrieve data from the external API.
app.intent('Default Welcome Intent', (conv) => {
    // Note: Moving this fetch call outside of the app intent callback will
    // cause it to become a global var (i.e. it's value will be cached across
    // function executions).
    return fetch(URL)
      .then((response) => {
        if (response.status < 200 || response.status >= 300) {
          throw new Error(response.statusText);
        } else {
          return response.json();
        }
      })
     .then((json) => {
       // Grab random quote data from JSON.
       const data = json.data[Math.floor(Math.random() * json.data.length)];
       const randomQuote =
          data.quotes[Math.floor(Math.random() * data.quotes.length)];
       conv.close(new SimpleResponse({
         text: json.info,
         speech: `${data.author}, from Google ` +
           `Developer Relations once said... ${randomQuote}`,
       }));
       if (conv.screen) {
         conv.close(new BasicCard({
           text: randomQuote,
           title: `${data.author} once said...`,
           image: new Image({
             url: BACKGROUND_IMAGE,
             alt: 'DevRel Quote',
           }),
         }));
       }
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM