Telegram bot using webscript.io


Posted:   |  More posts about lua telegram webscript

Telegram recently released their official Bot API. It make writing bot so easy compared to building your own client using the client API.

The only requirement for your bot is that an HTTPS endpoint that you can tell TG where to forward the incoming message from user. Being an HTTPS endpoint, it mean you need to have a valid SSL cert for your domain (if you haven't got one yet).

Another option is to use free hosting that provide you with HTTPS endpoint. There are a number of them. Among others:-

  • Heroku - Provide HTTPS endpoint for .herokuapp.com
  • Openshift - https://yourname-appname.rhc-cloud.com/
  • Google App Engine - https://yourname.appsppot.com/

To test directly from your laptop, use service such as ngrok.com.

But in this post I want to mention another alternative that is using webscript.io script as endpoint for TG bot. After signing up to the service, just create new Lua script like below:-

Then you need to create your bot using BotFather through your Telegram app. Once you get the auth token, replace tg_token variable in the script above with your auth token. Before the script can start accepting messages from Telegram, you need to tell TG using the setWebhook API method. So you have to make a request to the webscript endpoint yourself like:-

curl 'https://demo-xxxx.webscript.io/script?admin_command=setURL&pass=xxxx'

If there's no error, all set now. You can also check the logging that Webscript.io provide to check for any error.

The only downside of Webscript.io is that it's not free. The script created under the free account will only last for 7 days. With the same amount of money, you can get a small VPS from Digital Ocean to run the bot + some other stuff as well. But if you're not interested in maintaining another server then this is a great service. This can also be your great excuse to learn Lua ;)

Comments powered by Disqus

About me

Web developer in Malaysia. Currently work at MARIMORE Inc building internet services using Python and Django web framework.

ImportError is an error message emitted by Python when it failed to load certain module as requested by programmer. It's a very common error when someone new to the language trying it out. This website on the same theme, will try provide help for newcomers on any technologies to overcome their first hurdle.

Try most of the examples you may find here on Digital Ocean cloud service. They provide excellent VPS at a very cheaper price. Using this referral link you'll get USD10 credits upon sign up. That's enough to run single VPS with 1GB RAM for a month.

Others

I can also be found at the following sites:-

  • http://k4ml.blogspot.com/
  • http://k4ml.github.io/
  • http://metak4ml.blogspot.com/
  • http://www.mydev.my/
  • http://github.com/k4ml/

Disclaimers

The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions.

Share