Доступ к API через Google Actions / Dialogflow - PullRequest
0 голосов
/ 27 сентября 2018

Я хотел запустить задание Jenkins через API Jenkins. Мы можем сделать это, нажав URL-адрес, похожий на «JENKINS_URL / job / JOBNAME / build»

Я хочу использовать API через действие Google / Dialogflow.

Есть ли какое-нибудь учебное пособие для выполнения аналогичного процесса, которого я хочу достичь?

1 Ответ

0 голосов
/ 27 сентября 2018

Вы должны взглянуть на образец кавычек диалога , который показывает, как выполнять внешние вызовы 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',
           }),
         }));
       }
    });
});
...