Harsh Gohil
Harsh Gohil

Reputation: 3

Google Assistant Session Entity Some time working sometime not working.. nodejs

i have one code.. that given from action on google .. sometime its working sometime its not.. help me if anyone have any idea.. session entity is not working properly

const dialogflowAPI = require('dialogflow');
const sessionClient = new dialogflowAPI.SessionEntityTypesClient();
const client = new dialogflowAPI.EntityTypesClient();
const entityList = ['measure','dimension','size'];
const size = ['top','bottom','high','highest','low','lowest'];
exports.entityList=entityList;
exports.size=size;
exports.createSessionEntityType = async function(conv,entityName,entityValues){
try{
    const sessionEntityType = {
    name: conv.body.session + '/entityTypes/'+entityName,
    entityOverrideMode: 1,
    entities: entityValues,
  };
  const request = {
        parent: conv.body.session,
        sessionEntityType: sessionEntityType,
  };
  console.log(sessionEntityType);
  const [response] = await sessionClient.createSessionEntityType(request);
} catch(e) { 
   console.log(e); 
} 

Upvotes: 0

Views: 145

Answers (1)

Nick Felker
Nick Felker

Reputation: 11970

The method to handle session entities is different for Actions on Google. Instead of calling an API, you provide the entities in your webhook response. The documentation shows the new way to provide this information. It also gives a code snippet for how you can do it in the Node.js library.

app.intent('input.welcome', (conv) => {
  conv.ask('make your choice: apple or orange?');
  // Set the fruit session entity values to 'apple' and 'orange'.
  const responseBody = conv.serialize();
  responseBody['sessionEntityTypes'] =  [ {
    name: conv.body.session + '/entityTypes/fruit',
    entities: [{
        value: 'APPLE_KEY',
        synonyms: [
          'apple', 'green apple', 'crabapple'
        ]
     },
     {
        value: 'ORANGE_KEY',
        synonyms: [
         'orange'
        ]
     }],
    entityOverrideMode: 'ENTITY_OVERRIDE_MODE_OVERRIDE'
  }];
  conv.json(responseBody);
});

Upvotes: 1

Related Questions