通过Google Actions / Dialogflow访问API

时间:2018-09-27 13:42:57

标签: jenkins actions-on-google google-assistant-sdk

我想通过Jenkins API触发Jenkins工作 我们可以通过点击类似于“ JENKINS_URL / job / JOBNAME / build”的网址来做到这一点

我想通过Google action / Dialogflow来访问API。

有没有可用的教程来完成我想要实现的类似过程?

1 个答案:

答案 0 :(得分:0)

您应该看一下Dialogflow quotes示例,该示例显示了如何进行外部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',
           }),
         }));
       }
    });
});