intrd / telegram-simple_phpbot
Telegram Simple PHP Bot - A different and simple approach to use Telegram Bot Plataform (No SSL or setWebhook needed)
Requires
- php: >=5.3.0
- intrd/php-common: 1.0.*-dev
This package is not auto-updated.
Last update: 2025-01-28 22:26:08 UTC
README
Telegram Simple PHP Bot - A different and simple approach to use Telegram Bot Plataform (No SSL or setWebhook needed)Installation
System requiriments & dependencies
$ sudo apt-get update & apt-get upgrade
$ sudo apt-get install curl git php5-curl php5-cli
$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Now download the package (Composer automatically install all dependencies)
$ git clone https://github.com/intrd/telegram-simple_phpbot && cd telegram-simple_phpbot
$ composer install -o
To check for update..
$ git pull && composer update
Usage
TL;DR: The sample.php file will check every 5s if someone is mentioning the bot @username or talking him in pvt. It process and reply based on his message w/ some custom triggers.
Steps to setup your bot
- Open Telegram, talk w/ the
http://telegram.me/BotFather
, setup a new Telegram Bot and take a note of yourBotID:Botkey
, something like:234015785:AAEsvIjg0AcWOINXR0Xt-TGLamuz9k8f10Y
- Create a copy of configuration file sample
cp config.ini.sample config.ini
- Edit
config.ini
and set yourbotkey
- Search on Telegram for your
@username_bot
and start a conversation.. - Now run
php sample.php
, it shows yourchatID
. Setdebug_chatid
onconfig.ini
. All bot activity will be forwarded to this conversation, for debbugin purpose. - Change the
trigger
to yourusername_bot
or something you want to trigger your bot replies on groups. - To check if someone is talking w/ your bot every 5 seconds use my bash daemon sample
./run.sh &
, orwatch -n5 php sample.php
or setup a cronjob - Now put him on a group..
- Test if your bot is replying when you mention his
trigger
, ask him aboutday of week
, say him some of$bads
, customizereply_get()
function.
Tips
Manually check (botid/botkey/chatid)
Browse to your bot URL: https://api.telegram.org/bot<botid>:<botkey>/sendmessage?chat_id=<chatid>&text=hello%20world!
in my sample https://api.telegram.org/bot234015785:AAEsvIjg0AcWOINXR0Xt-TGLamuz9k8f10Y/sendmessage?chat_id=65628842&text=hello%20world!
, if the bot says Hello World!
to you, its ok. PS: group chats use negative chatIDs, -<chatid>
If you prefer not to use daemons (SSL Webserver)
With a SSL webserver serving your sample.php, simply setup your hook URL by browsing:
https://api.telegram.org/bot<botid>:<botkey>/setWebhook?url=http://yourwebserver/sample.php
..and Telegram server will load this URL every time the bot receive a msg.
That's all,
Script this 4 your needs and respect the CC license, thanks!