Bot Framework V4 Node.js-如何通过主动消息查找和结束主动对话框

时间:2020-07-16 17:48:57

标签: javascript node.js botframework

我有一个Dialogbot启动MainDialog。 MainDialog是具有多个瀑布图步骤的组件对话框。瀑布步骤之一启动了一个新的名为PAYMENT_DIALOG的ComponentDialog

return await stepContext.beginDialog(PAYMENT_DIALOG);

PAYMENT_DIALOG有两个瀑布步骤:

  1. 带有提示(WAITING_FOR_PAYMENT_PROMPT)和一个
  2. 的showPaymentLinkStep
  3. 确认步骤,应在收到付款后开始。

showPaymentLinkStep打开带有OpenUrl动作的按钮,该按钮允许用户支付一些费用。提示正在等待来自付款服务提供商(PSP)的付款状态更新。一旦进入,第二步就需要采取行动(向用户提供的产品再次有机会开始付款过程。

如果付款交易的状态发生变化(已付款,已取消或失败),则PSP将后请求发送到bot(reindex.js中的reify服务器)

在Index.js中,我有一条主动消息“ construction”,并希望在PSP向我的机器人发送发布请求后立即结束WAITING_FOR_PAYMENT_PROMPT。


// Listen for incoming payment status changes.
server.post('/webhook/payment', async (req, res) => {
    const conversationReference = conversationReferences[payment.metadata.conversationId]; //conversationId is in metadata of payment request
    await adapter.continueConversation(conversationReference, async turnContext => {
        // if payment status ===  paid, create dialogcontext and end active dialog (I hope)
        if (req.payment.status === 'paid') {
            const dialogSet = new DialogSet(dialogState);
            const dialogContext = await dialogSet.createContext(turnContext);
            await dialogContext.endDialog();
            await conversationState.saveChanges(turnContext);
        }
    });
});

这将结束MAIN_DIALOG,而不是WAITING_FOR_PAYMENT_PROMPT(我的目标)。这是有道理的,因为MAIN_DIALOG在堆栈的顶部。

我试图通过递归找到活动对话框,但是这没有用,因为dialogContext.child返回未定义,并且函数返回的结果与调用dialogContext.stack相同。

function getInnermostActiveDialog(dc) {
    const child = dc.child;
    return child ? getInnermostActiveDialog(child) : dc.activeDialog;
}

dialogContext.stack显示:

[
  {
    "id": "MAIN_DIALOG",
    "state": {
      "dialogs": {
        "dialogStack": [
          {
            "id": "WATERFALL_DIALOG",
            "state": {
              "options": {},
              "values": {
                "instanceId": "1c4d659f-e402-d614-6528-23ffdd7d6ade",
                "proof": true,
                "email": "<e-mailadres>"
              },
              "stepIndex": 3
            }
          },
          {
            "id": "PAYMENT_DIALOG",
            "state": {
              "dialogs": {
                "dialogStack": [
                  {
                    "id": "WATERFALL_DIALOG",
                    "state": {
                      "options": {},
                      "values": {
                        "instanceId": "aa0914a9-6579-6b36-4b90-e74b8a526912"
                      },
                      "stepIndex": 0
                    }
                  },
                  {
                    "id": "WAITING_FOR_PAYMENT_PROMPT",
                    "state": {
                      "options": {
                        "retryPrompt": "Still waiting for payment."
                      },
                      "state": {}
                    }
                  }
                ]
              }
            },
            "version": "1271917064"
          }
        ]
      }
    },
    "version": "-114918493"
  }
]

根据文档,这应该是正确的方法:

从集合中对话框之外的代码中,使用DialogSet.createContext创建对话框上下文。然后使用对话框上下文的方法来管理集合中对话框的进度。

但是在我的代码中,创建了dialogContext,所有对话框似乎在其中都在其中),但是dialogContext.endDialog()不会导致WAITING_FOR_PAYMENT_PROMPT的结束(并转到下一个)步骤。)

一些帮助非常感谢

Bot framework v4 Node.js: how to go to next waterfall step based on external trigger (post request)中此问题的背景 此解决方案的想法来自:https://stackoverflow.com/a/57780273/7095607

0 个答案:

没有答案