我在Bots.Business 中创建了机器人
我的机器人程序将网页链接发送给用户。
用户可以:
- 单击此链接并转到网页
- 单击此链接并立即关闭浏览器
- 不要单击链接
如何检查该用户是否访问此网页?
我们有几种方法:
-
将任何机密信息放在您的网页中。用户必须复制这个秘密,并在访问网页后发送给机器人。机器人可以检查这个秘密。如果秘密是有效的-用户访问网页。否则不会。
这是一种更容易开发的方式,但对用户来说却不是。
-
使用webhook库这对发展来说更加困难。易于用户使用。
命令/生成-您需要在之前以管理员身份运行此命令
let webhookUrl = Libs.Webhooks.getUrlFor({
// this command will be runned on webhook
command: "/onWebhook",
// this text will be passed to command
content: "http://yourpage.com",
// execute for this (current) user
user_id: user.id
})
Bot.sendMessage(webhookUrl);
您将拥有webhookUrl。你现在可以把这个webhook url放在你网页上的1px不可见iframe中:
<IFRAME width=1 height=1 src=http://webhookUrl scrolling=no frameborder=0></IFRAME>
你也可以在你的页面上向这个webhook url 发出GET或POST请求
对于用户:
命令/getLinklet currentTaskUrl=";http://yourpage.com"User.setProperty("currentTaskUrl"、"currentTaskUrl"、"string"(Bot.sendMessage("链接:"+当前任务URL(
命令/onWebhook:
// it will be executed on webhook
let webPage = content;
let expectedPage = User.getProperty("currentTaskUrl")
if(webPage==expectedPage){
// user just visit web page
// your code here
User.setProperty("currentTaskUrl", null, "string")
}else{
// user visit another web page with this webhook
// may be he make refresh prev page or etc
}