Search code examples
dialogflow-esactions-on-googledialogflow-es-fulfillment

How can we configure Context & Events in Inline Code editor


How can we configure Context & Events in Dialogflow Inline Code editor? I have tried the options below, but none of these is working.

app.intent('test1', (conv)=>{
 conv.Context.set({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }});   
  conv.followupEventInput.set({
     'name':'Event_Sample',
      "parameters": {
      "parameter-name-1": "parameter-value-1",
      "parameter-name-2": "parameter-value-2"
    },
    "languageCode": "en-US"
    });
});
//conv.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }});   
//conv.setfollowupEventInput({ name: 'event-name', languageCode: 'en-US', parameters: { parameter-name-1: 'parameter-name-1', parameter-name-2: 'parameter-name-2' }});

Solution

  • To set a context you need to call conv.contexts.set() and provide a name and lifespan for the context. Optionally you can provide parameters that you can send to a next turn in the conversation. An example would be:

    conv.contexts.set("Foo", 5, {foo: "bar"});
    

    In your code example calling Context.set() instead of contexts.set() and you used { } around the parameters, so you are providing one object instead of three seperate values. This is most likely why you context isn't working.

    The same goes for your follow-up event. You are calling FollowupEventInput() instead of followup() and you have are setting the parameters with a single object due to the { }, so remove those.

    More info and examples on context and follow-up events can be found in the docs.