Download the open source Bot Libre Community Edition and install Bot Libre on your own server
Help

How can I save list of values in conversation object.

by BM posted 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: 1288, today: 0, week: 0, month: 2

Id: 22877023
Tags: self
Posted: Jul 19 2018, 4:32
Replies: 1
Views: 1369, today: 1, week: 2, month: 11
0 0 0.0/5