如何从会话对象获取当前库名称

时间:2018-06-28 01:34:54

标签: botframework

我想在任何对话框瀑布步骤中从Session对象获取当前库名称。 目前,我正在调用session.dialogStack()并从堆栈顶部的对话框中提取ID。有更好的方法吗?

1 个答案:

答案 0 :(得分:0)

正如您在问题中提到的以及Gary Gary所评论的那样,获取当前对话框的库ID的正确方法是使用session.dialogStack()。对于没有name参数的UniversalBot,该值默认为"*"

UniversalBot reference

示例:

bot.dialog('greeting', [
  (session, args) => {
      let currentStack = session.dialogStack()
      // [ { id: '*:greeting', state: { 'BotBuilder.Data.WaterfallStep': 0 } } ]

      console.log(currentStack[currentStack.length - 1])
      // { id: '*:greeting', state: { 'BotBuilder.Data.WaterfallStep': 0 } }

      console.log(currentStack[currentStack.length - 1].id)
      // '*:greeting'

      // Separate the library name from the dialogId by calling 
      // String.prototype.split() on the stack.id. The splitter we'll use is ":".
      console.log(currentStack[currentStack.length - 1].id.split(':'))
      // [ '*', 'greeting' ]

      session.endDialog('Bye from "greeting"!')
  }
]).triggerAction({matches: /hi/ig})