简体   繁体   中英

How to connect to Actions builder project to update type entities?

I've got a project build migrated from AOG + Dialogflow to Actions Builder. I need to update (or insert new) type entries with the REST API. To do that action I've found an endpoint, that gives the ability to update the whole project along with entities: https://developers.google.com/assistant/actions/api/reference/rest/v2/projects.draft/write

However, I can't connect to that endpoint due to 401 error. Before that I've tried to emulate a similar request to another endpoint, which allows reading the project:

https://developers.google.com/assistant/actions/api/reference/rest/v2/projects.draft/read

Obviously, I've got the same error here. Also, I've found this repo - https://github.com/actions-on-google/assistant-actions-nodejs which adds a wrapper for easier manipulation with the REST API, but it also doesn't contain any information on how to properly authorize to get access to an app.

Can please somebody suggest how authorization should be done to start using this REST API?

Using Actions Builder, the type entities can be updated directly in your webhook calls rather than calling an API in parallel.

Look up the names of the types you want to override in Actions Builder and set the conv.session.typeOverrides field in your response.

Here's a code example of how it might be done:

const app = conversation()

// `app.middleware` will run on every invocation call
app.middleware(conv => {
  // ...
  // Obtain `trackTitles` and `trackGenres`
  // ...
  conv.session.typeOverrides = [{
    name: 'track',
    mode: Mode.TypeReplace,
    synonym: {
      entries: Array.from(trackTitles).map(title => ({
        name: title,
        synonyms: [title],
      })),
    },
  }, {
    name: 'genre',
    mode: Mode.TypeReplace,
    synonym: {
      entries: Array.from(trackGenres).map(genre => ({
        name: genre,
        synonyms: [genre]
      }))
    }
  }]
})

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