【问题标题】:input password webchat输入密码网络聊天
【发布时间】:2019-09-11 10:59:39
【问题描述】:

我在 webchat 中输入密码时遇到问题。我使用 Sample - Customize Web Chat with Password Input Activity 用于密码输入卡,当我输入错误密码时,它会显示一条消息,例如密码错误,请重试,但是当我输入密码时表单我需要显示另一条消息。

我使用了这个代码。

if (card.activity.type === 'message') {
        if (
          card.activity.from.role === 'bot' &&
          (card.activity.text === getLoginMessage(this.props.language) ||
            card.activity.text === getLoginRetryMessage(this.props.language))
        ) {
          let message = card.activity.text;
          if (!this.hasSubmittedPassword && (card.activity.text === getLoginRetryMessage(this.props.language))) {
            message = "Please fill the form and click enter in order to complete your request.";
          }
          return children => (
            <ConnectedPasswordInputActivity
              promptMessage={message}
              passwordPlaceholder={this.props.literals.password}
              language={this.props.language}
              handlePasswordSubmit={this.handlePasswordSubmit}
            >
              {next(card)(children)}
            </ConnectedPasswordInputActivity>
          );
        }

Refer to the image please

【问题讨论】:

  • 接受/投票支持更大的 Stack Overflow 社区和任何有类似问题的人。如果您觉得我的回答足够,请“接受”并点赞。如果没有,请告诉我我还能提供哪些帮助

标签: botframework web-chat


【解决方案1】:

这很难确定,因为您引用了很多隐藏代码,但我怀疑这个问题与您的 hasSubmittedPassword 函数和您的检查有关。

你正在匹配

  1. 一条消息
  2. 来自机器人
  3. 文本等于getLoginMessagegetLoginRetryMessage 返回值

这些都通过了您的检查(根据所附图片)。

然后您检查hasSubmittedPassword(显然)正在通过,然后再次检查getLoginRetryMessage(???)。第二次检查是不必要的,因为如果第一次检查(card.activity.text = this.getLoginRetryMessage(this.props.language) 未成功),您将不会出现在此 if 语句中。

这可以简化为:

if (!this.hasSubmittedPassword) {
    message = "Please fill the form and click enter in order to complete your request.";
}

话虽如此,您对if(!this.hasSubmittedPassword) {...} 的使用只是检查是否有返回值。此函数可能会或可能不会返回正确的值,但您的检查并不关心。它只想知道 IF 有一个值。如果您的逻辑设置为始终返回某些内容(即真、假、是、否,再试一次),那么它将始终通过。

据我所知,如果您的前三项检查通过,那么您将始终收到第二条消息。

希望有帮助!

【讨论】:

  • 您好,谢谢您的回答。我只想在 inputPassword 字段中输入密码时显示一条特定消息,当我在 inputPassword 字段中输入密码时显示另一条消息,但它不正确,我想显示一条消息,例如密码错误,请重试。
猜你喜欢
  • 1970-01-01
  • 2012-08-22
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2020-12-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-17
相关资源
最近更新 更多