当Intent被调用时可以发送应答消息给bot的用户,当应答生成时,将产生ResponseReceived
事件。
属性 | 描述 |
---|---|
Text | 文本消息 |
Format | 格式: Html, Markdown, Plain 和 Xml. |
Hint | 对于bot期望的下次用户的输入的提示 |
Type | 应答类型: message 或 other. |
简单应答
[Expression("Hello Bot")]
public void HelloBot(Context context, Result result)
{
result.SendResponse("Hello Bot developer!");
}
接收应答
var bot = new OscovaBot();
bot.MainUser.ResponseReceived += (o, args) =>
{
Console.WriteLine($"Bot: {args.Response.Text}");
};
HTML格式
[Expression("Hello Bot")]
public void HelloBot(Context context, Result result)
{
var response = new Response
{
Text = "<b>Hello bot developer!</b>",
Format = ResponseFormat.Html
};
result.SendResponse(response);
}
延时的回复
[Expression("Hello Bot")]
public void HelloBot(Context context, Result result)
{
result.SendResponse("Hello Bot Developer!", TimeSpan.FromSeconds(2));
result.SendResponse("Glad you are here.", TimeSpan.FromSeconds(5));
}
对于工作的定时响应,外部定时器实现是必不可少的
var bot = new OscovaBot();
var timer = new Timer { Interval = 1000 };
timer.Elapsed += (sender, eventArgs) =>
{
bot.Timer.PerformTick();
};
timer.Start();