1

my project is to have a chatbot that can sell electronic device like resistor, diode and so on. There are many type of resistor and diode

I have my intents in dialogflow so when user choose one item I need to store it into php session variable so when user have finished so I need to restore that items in session variable but it doesnt work

Recieve dialogflow intent that is called "tomar_cantidad"

  if (intent_recibido("tomar_cantidad")) {

  $modelo = obtener_variables3('modelo');
  $cantidad = obtener_variables2('cantidad');
  //enviar_texto(print_r($cantidad));

  $datos_usuario = array('modelo'=>$modelo,'cantidad'=>$cantidad);

   $_SESSION['datos_usuario'][]= $datos_usuario;

   enviar_texto(print_r($_SESSION['datos_usuario']));
   }

enviar_texto is a method to send information to dialogflow(that is for testing purposes).

I recieve session variable but only store the last item that user choose not all items

  • StackOverflow works best when you have a concrete problem that you have attempted to solve, but can't figure out, or which is generating error messages which you are unable to fix. It is not clear what your question is or what problem you're having. See [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Prisoner Aug 09 '20 at 22:10
  • I changed my question – user2676907 Aug 10 '20 at 19:24

1 Answers1

2

The issue is that the PHP $_SESSION variable is tied to an HTTP session, which is usually implemented with an HTTP cookie. But Dialogflow doesn't manage HTTP cookies when it sends messages to a webhook, so each fulfillment call is a new session each time.

You have a few ways you can approach this:

  • Get the Dialogflow session ID and store the information against this ID

  • Store any values you want to store between turns in the conversation as a parameter in an Output Context. You should set the lifespan for the Context to a large number, 99 is typical, or re-set this as the Output Context each time. Then, you can read the parameter in the named Context when you need the information.

Prisoner
  • 49,922
  • 7
  • 53
  • 105