Telegram Bot

I develop a Bot for the Telegram Messenger.

You can see the code on Github. You can easily write your own plugins to extend the Messenger. Feel free to create Pull Request in my repository.

Version History

0.9.21 – Added Google Search Plugin

0.9.2 – new API, differentiation between different message types

0.9.1 – Full support for Plugins + availability of MySQL

0.8 – Initial release

Contributing

Want to write more plugins or improve the bot? Feel free to clone git repository and start working. See this guide for more information.

 

Usage

You will need a PHP-enabled Webserver, a SSL-certificate for your domain, a MySQL database (optional) and a Telegram Bot Key. You will also need to download some scripts from other locations.
Some plugins may need further configuration steps.

Create a new Telegram Bot. Make sure you disable the privacy mode – otherwise some plugins won’t work!

Clone the git repository onto your server and create a new host for it (e.g. telegram.example.com). Make sure you have SSL enabled for this host with a valid certificate. You can get one from StartSSL or via letsencrypt for free or create your own certificate.

Create a new file in the root directory (where config.php is) and call it secret.php. This file will contain all sensible information, such as passwords and API keys.

You have to do the following definitions (replace it by valid data!).

<?php
 // TELEGRAM 
 define("TELEGRAM_API_TOKEN", "YOUR_TELEGRAM_TOKEN");
 define("TELEGRAM_LISTENER_URL", "https://telegram.example.com/listener.php");
 define("BOT_OFFICIAL_NAME", "YOUR_BOT_NAME");

 // DATABASE
 define("dbserver", "localhost");
 define("dbpassword", "YOUR_PW");
 define("dbusername", "YOUR_USER");
 define("dbdatabase", "YOUR_DB");

 // MEMES
 define("meme_api_login", "YOUR_MEME_LOGIN");
 define("meme_api_pw", "YOUR_MEME_PW");

 // WEATHER
 define("weather_appid", "YOUR_OPEN_WEATHER_API_KEY");

 // WOLFRAM
 define("WOLFRAM_API_KEY", "YOUR_WOLFRAM_API_KEY");
?>

Then you just have to call https://telegram.example.com/register.php once to make Telegram push new messages to your server – that is all you need.

5 Replies to “Telegram Bot”

  1. can you help me how to interation telegeram use mysql database
    example
    i am send message to table message_out in mysql telegram respon my message automaticly

    Thanks You

    1. Hi,
      I don’t think I already understood what you are about to do.

      So you want to save a message to a MySQL table and want the Telegram Bot to read this Message from the Table and send it to you?

      If this is the case: Would you like the Bot to send the message to you or would you like it to reply with the given text from the Database when you send a message to the Bot?

  2. i can setup telegram bot can you help me to use your source and run it?
    i add my email that can contact with other
    thanks

    1. Hi,
      what exactly is your problem when setting up the bot?
      As described here you need a webserver with php, an SSL certificate (e.g. obtained by letsencrypt) and a key for your telegram bot.
      In your Telegram Client (Phone or PC) you have to contact @botfather and create a new bot you would like to use. Then add the token to the “secret.php” in the root folder of the bot together with your domain name for the listener and you are ready to go. To get all plugins working you have to get some more API tokens or logins (for memes, weather and wolfram alpha).

      Please be a bit more specific with your questions 😉

      Regards
      Lennart

Comments are closed.