当`session`对象不可用时,在Bot Framework中读/写bot用户数据

时间:2017-10-17 07:36:15

标签: node.js bots botframework

我想在Microsoft的Bot Framework提供的bot的用户数据存储中存储一个简单的键值对。

通常很容易做到:

session.userData.key = value;

但是,我希望在session对象不可用时,在处理所有传入消息的事件处理程序中执行此操作:

bot.on('incoming', incoming => {
  // Check whether user asked to switch on debug mode.
  if (incoming.text === 'debug on') {
    console.log('Enabling debug mode.');
    // TODO FIXME - we need to save the result to bot memory.
  }
});

还有其他方法可以从主app.js文件或事件处理程序保存到机器人内存吗?

1 个答案:

答案 0 :(得分:2)

我找到了解决方案,即使用@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case 1: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // permission was granted, yay! Do the // contacts-related task you need to do. } else { // permission denied, boo! Disable the // functionality that depends on this permission. Toast.makeText(MainActivity.this, "Permission denied to read your External storage", Toast.LENGTH_SHORT).show(); } return; } // other 'case' lines to check for other // permissions this app might request } }

UniversalBot.loadSession()

加载bot.on('incoming', incoming => { // Load the user session so that we can save values to userData. bot.loadSession(incoming.address, (error, session) => { if (!error) { // work with the session object as usual } }); }); 对象后,您可以照常使用sessionsession.send()