简体   繁体   中英

Access an API through Google Actions/Dialogflow

I wanted to trigger a Jenkins job through the Jenkins API we can do that by hitting the URL similar to "JENKINS_URL/job/JOBNAME/build"

I want to hit the API via Google action/Dialogflow.

Is there any tutorial available to do a similar process that I want to achieve?

You should take a look at the Dialogflow quotes sample, which shows how to make external API calls:

// 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',
           }),
         }));
       }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM