Syn Bot /OSCOVA 创建意图(4)

实现方式是一个public void的方法,可以带有Context和Result参数。

来看下声明:

[Expression("How is the weather?")]
public void Weather(Context context, Result result)
{
    //Do something.
}

上下文(Context):提供一组信息,包含当前用户的会话上下文,允许修改删除上下文的相关参数,有一个SharedData属性,可以让开发人员存取限定于用户会话的对象。

结果(Result):Oscova框架生成的针对当前用户消息的执行结果,它的Entities属性包含了所有识别到的实体对象,它的CurrentIntent属性表示当前调用的意图对象信息。

意图的参数是可选的,以下实现方式都是支持的:

[Expression("How is the weather?")]
public void Weather()
[Expression("How is the weather?")]
public void Weather(Context context)
[Expression("How is the weather?")]
public void Weather(Result result)
[Expression("How is the weather?")]
public void Weather(Context context, Result result)

名称规则

可以使用特性重写:

[Expression("Find a hotel nearby")]
[Intent(Name="nearestHotel")]
public void FindHotel(Context context, Result result)

当没有找到任何匹配的常规意图,使用默认意图来返回一些信息:

[Fallback]
public void DefaultFallback(Context context, Result result)
{
    result.Send("Can you please rephrase that for me?");
}

支持强制调整意图的分数。

[Expression("@sys.positive")]
[Intent(MinScore = 0.7)]
public void CommitToDatabase(Context context, Result result)
{
    //User said "Yes". Do something essential here.
}

支持显式禁用意图

[Trait(Type = "#feedback")]
public void Feedback(Context context, Result result)
{
    //Do something and then...

    //Disable the specified intent for the next 2 requests.
    result.User.DisabledIntents.Add("IntentA", 2);

    //Disable the specified intent permanently for this user.
    result.User.DisabledIntents.Add("IntentB");
}
原文地址:https://www.cnblogs.com/mrtiny/p/9081708.html