ご存知でしたボットのリブレー無料主催 フォーラム のためにお客様ご自身のウェブサイトまたはモバイルアプリのか?
Help

How can I save list of values in conversation object.

による BM 掲載 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: 1487, today: 0, week: 2, month: 28

Id: 22877023
タグ: self
掲載: Jul 19 2018, 4:32
回答: 1
眺望: 1554, 今日の: 1, 週間: 6, 月: 44
0 0 0.0/5