Spędzić swój własny bot-platforma z botem Libre przedsiębiorstwa bot platformy
Help

How can I save list of values in conversation object.

w BM wysłany 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: 1491, today: 2, week: 3, month: 32

Identyfikator: 22877023
Tagi: self
Wysłany: Jul 19 2018, 4:32
Odpowiedzi: 1
Widok: 1558, dziś: 4, tydzień: 4, miesiąc: 48
0 0 0.0/5