Atualize para nosso Platinum serviço e deixar-nos a construir o seu bot para você
Help

How can I save list of values in conversation object.

por BM postado Jul 19 2018, 4:32

As of my understanding conversation is globally available in self script. Is there any other way of saving a variable and accessing it. How can we save a list of variables like an array in conversation object. I am doing the following but its not working;

function init() {

      var myArray = new Array();
     conversation.itemList = myArray;

}

function add_item() {
  var item = new Array();
  item[0] = 'first item';

 item[1] = 'second item' ;

conversation.itemList = item;

}

function show_items() {

  var items = conversation.itemList;

  return items.length(); // returns zero, There are no items in array?

}


by admin posted Jul 19 2018, 9:10
How are you calling these methods?

The "conversation" variable is an object specific to the current conversation. You can store any data on it and it will be persisted with the conversation and accessible for the duration of the conversation.

Make sure you are no calling init() after add_item() as that would reset the itemList attribute to an empty array.

You can also store data on the user object using the "speaker" variable, or globally on the bot symbol #self, or globally on any other symbol your choose using #symbolName.

Here is an example of a script that uses the conversation variable to store data.

https://www.botlibre.com/script?id=13979782

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 801, today: 0, week: 0, month: 0

Id: 22877023
Tags: self
Postado: Jul 19 2018, 4:32
Respostas: 1
Pontos de vista: 861, hoje: 1, semana: 1, mês: 1
Eu tenho certeza que
Bandeira post como ofensivas, ou em violação das regras do site