Laravel

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.

5 thoughts on “Laravel: Create Telegram Bot Application without Botman Studio

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × 4 =