6

我的机器人将用户名存储在数据库中,并且数据库有时会向会话发送一条消息“setname username”。示例铆钉:

+ setname *
- <set name=<formal>>

+ (what is my name|who am i)
- You're <get name>, right?

+ didntlike
- {topic=nlike}Why?

> topic nlike

+ *
- {topic=random}Thanks for charing.

< topic

+ *
- I don't have a reply for that.
- Try asking that a different way.

问题是当用户处于由 * 退出的“nlike”之类的主题中并且我发送消息以设置名称时,对话退出该主题。

预期对话:

Me: hello
Bot: I don't have a reply for that.
Me: didntlike
Bot: Why?
Me: setname John
Bot:
Me: I didn't like because you are ugly.
Bot: Thanks for charing.
Me: Who am I?
Bot: You're John, right?

有没有办法在开始块中处理它?我尝试了不同的语法,但没有积极的结果。我想到了类似的东西:

> begin

+ setname *
- <set name=<formal>>

+ request
- {ok}

< begin

一种解决方法是在所有主题中添加相同的触发器,但我需要一个更好的解决方案,因为随着我的 rive 文件变大,这种方法很容易出错。

====根据尼尔森的回答尝试的代码=====

> begin
    + request
    - {ok}{topic=specialtriggers}
< begin

> topic specialtriggers

+ setname *
- <set name=<formal>>

< topic

+ (what is my name|who am i)
- You're <get name>, right?

+ didntlike
- {topic=nlike}Why?

> topic nlike

+ *
- {topic=random}Thanks for charing.

< topic

+ *
- I don't have a reply for that.
- Try asking that a different way.

我认为将主题添加到 {ok}{topic=specialtriggers} 会使该主题之外的所有触发器都失败。预处理后,Rivescript 应该回答它是否是特殊触发器,否则搜索正常触发器。

4

2 回答 2

0

根据Noah Petherbridgechatbots.org上的回复,一个可行的解决方案是使用主题继承:

> topic specialtriggers
    + setname *{weight=9991234}
    - <set name=<star1>>
< topic

> topic random includes specialtriggers
    // you don't actually need to put anything inside here, since triggers
    // without a topic are in the "random" topic automatically, but this
    // topic declaration line will make "random" include "important"
< topic

// but for your other topics, include the specialtriggers one
> topic nlike includes specialtriggers
    + *
    - {topic=random}Thanks for caring.
< topic
于 2018-01-21T23:43:38.883 回答
0

如果您的问题只是关于如何始终使用begin块预处理用户消息,答案是:

  • 不需要在开始块中输入触发器。A+ request是任何用户消息的通用表示。
  • 如果您想限制仅从当前主题开始块中匹配的触发器,则{ok}标记就足够了。

修改您的代码如下

+ didntlike
- {topic=nlike}Why?

> topic nlike
    + *
    - Thanks for charing.
< topic

> begin
    + request
    - {ok} (Preprocessed in begin)
< begin

尝试以下消息序列didntlikehello您将看到回复附加了(Preprocessed in begin)

  • 否则,begin 块中的回复需要添加一个主题 where(哪个主题)来获取触发器和回复。如果您想获取setnamein randomtopic 的触发器,可以将 begin 块添加到您的第一个代码片段的末尾。

RiveScript 代码

> begin
    + request
    - {ok}{topic=random}
< begin

在这种情况下,服务请求后的主题setname是 topic random

于 2018-01-16T09:42:18.923 回答