Laravel: Create Telegram Bot Application without Botman Studio
Installation
We are using Botman package, and Botman Telegram Driver.
Configure .env
Use Bot Father to create new bot and get the API Token for the bot, store it in .env
.
TELEGRAM_TOKEN="your-bot-api-token"
Telegram End Point
Create a route & controller for your Telegram Bot to use after this (webhook).
In TelegramController
, add the following:
Now you are done preparing for next part.
Webhook
For development purpose, you can use valet share
to have a live server. For Windows / Linux, you can install ngrok.io to have a live server.
valet share
is actually running a ngrok.
Run command valet share
and and then register our app with Telegram using php artisan botman:telegram:register
command.
CSRF Token
In AppHttpMiddlewareVerifyCsrfToken
, disable CSRF token for /telegram
route.
One you are done setting up the webhook, open up your Telegram, start talk with your bot, /hi
. You should received response from your bot.
Thank you.
You’re welcome. 🙂
Abam Nasrul,
ada tak yang pakai botman?
Btw yg ini jenis webhook kn?
takda kalau yg pakai botman, tak buat sbb tak flexible to my project. haha..
ya, supposed webhook.
Thankyou… mantap…