0

We are facing issues while managing multiple user interaction at the same time in Dialogflow. How we can manage user unique session as we are using custom event which will process our 3rd party API and then return a response to the specific user. To manage User unique session We try Dailogflow Set/Get Context method, to set Context with Unique Id (using this id will store API response to the Redis server) from the first intent when a user makes a first request then will traverse that Unique Id through the custom event. Will get that Unique Id from Context and grab data from Redis server which we stored in first intent. We used agent.set.context() to set unique id but this method is not working with "dialogflow-fulfillment"  version ^0.5.0, To get this work we have updated the version with "^0.6.1". But this will provide other error like "UnhandledPromiseRejectionWarning: Error: No responses defined for platform: null".

Required Output: Context set with a unique id and will get a proper response. Current Output: UnhandledPromiseRejectionWarning: Error: No responses defined for platform: null

    async function searchFromAPI(agent){

        axios.post('https://testApi.com', searchString.data, {headers: headers})
        .then((resp) => {
                response.data = resp;
                redisClient.set(sessionId, JSON.stringify(response));
            }
        }).catch(error => {
            response.error = true;
            response.message = error.response.statusText;
            redisClient.set(sessionId, JSON.stringify(response));
        });
        await customsleep(2000);
        const sessionId = uuid.v4();
        const contextData = {'name':'userSession','lifespan': 5,'parameters':{'sessionId':sessionId}};
        agent.context.set(contextData);
        console.log(contextData);
        agent.add('We are processing your request, Could you please wait?');
        agent.add(new Suggestion("Yes"));   
        agent.add(new Suggestion("No"));    
    }

    // wait for 4.5sec and call custom event
    async function followOne(agent){    
        await customsleep(4500);
        agent.setFollowupEvent('followUpTwo');
    }
    // wait for 4.7sec then red API response from redis server and return 
    async function followUpTwo(agent){  
        await customsleep(4000);
        sess = session;
        //get context
        const response = agent.context.get('userSession');
        // get the sessionId, Get the data from redis server
        agent.add(response);

    }
    async function PleaseWait(agent){
        await customsleep(3500);
        agent.setFollowupEvent('followUpOne');
    }
Tom Smith
  • 1
  • 1
  • 2

2 Answers2

0

I found the only workaround to reassign a new context object via context.set(ctx). Then it worked.

//update context to show full menu
  let context = agent.context.get('user_data');
  if (!context) throw "User_data context ius nod defined in PreferrenceAdd"

  let context2 = new Object();
  context2 = {'name': 'user_data', 'lifespan': 40, 
  'parameters': context.parameters}; 
  console.log("ctx: = " + JSON.stringify(context2));
  context2.parameters.new = false;
  context2.parameters.refresh = true;
  agent.context.set(context2);
Sergey Y.
  • 51
  • 6
-1

Check this resource on how to set a new Dialogflow outgoing context dialogflow webhook-client.

I hope this helps you?

Terungwa
  • 395
  • 3
  • 18