Class: Session

Session()

new Session()

封装对session的操作。DuerOS提过了多轮对话的能力,也能替Bot管理多轮对话,无须Bot自己维护session状态。 同时,也提供了Session存储,Bot还可以将对话的状态保存session中,自己处理多轮逻辑。 但是,存储在session中的数据,DuerOS是无法将其自动应用到下一轮的query解析中,对话状态的维护需要Bot自己完成
Source:

Methods

clear()

清空session的所有attributes
Source:

getData(field, def) → {string|Object}

从session中获取一个属性的值
Parameters:
Name Type Default Description
field string 属性名称
def string null 默认值
Source:
Returns:
Type
string | Object
Example
this.getData('status');
this.getData('status', '1');

setData(field, value, def) → {null}

将一个值存储到session中 注意: value必须是字符串
Parameters:
Name Type Default Description
field string 属性名称
value string 属性值
def string null 默认值
Source:
Returns:
Type
null
Example
this.setData('status', '1');
this.setData('status', '1', '8');

toResponse() → {Object}

将session输出response的格式
Source:
Returns:
Type
Object

Session(data)

new Session(data)

Parameters:
Name Type Description
data Object 请求bot的session数据
Source:

Methods

clear()

清空session的所有attributes
Source:

getData(field, def) → {string|Object}

从session中获取一个属性的值
Parameters:
Name Type Default Description
field string 属性名称
def string null 默认值
Source:
Returns:
Type
string | Object
Example
this.getData('status');
this.getData('status', '1');

setData(field, value, def) → {null}

将一个值存储到session中 注意: value必须是字符串
Parameters:
Name Type Default Description
field string 属性名称
value string 属性值
def string null 默认值
Source:
Returns:
Type
null
Example
this.setData('status', '1');
this.setData('status', '1', '8');

toResponse() → {Object}

将session输出response的格式
Source:
Returns:
Type
Object