Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

telegram bot - How to check site visiting after link clicking in bot created with Bots.Business

I have bot created in Bots.Business

My bot send link for web page to user.

User can:

  • click on this link and go to web page
  • click on this link and immediately close browser
  • do not click link

How to check that user visit this web page?

question from:https://stackoverflow.com/questions/65626264/how-to-check-site-visiting-after-link-clicking-in-bot-created-with-bots-business

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

We have several ways:

  1. 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.

  2. 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

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...