We have several ways:
Place any secret info in your web page. User must copy this secret and send to bot after web page visiting. Bot can check this secret. If secret is valid - user visit web page. Else not.
It is more easy way for development but not for users.
Use webhook lib
It is harder for development. Easy to users.
Command /generate - you need run this command as admin before
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);
You will be have webhookUrl. You can place this webhook url in 1px invisible iframe on your web page now:
<IFRAME width=1 height=1 src=http://webhookUrl scrolling=no frameborder=0></IFRAME>
Also you can make GET or POST request in your page to this webhook url
For user:
Command /getLink
let currentTaskUrl = "http://yourpage.com"
User.setProperty("currentTaskUrl", currentTaskUrl, "string")
Bot.sendMessage("Link: " + currentTaskUrl)
Command /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
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…