H
H
Helcurt2020-11-15 16:41:06
PHP
Helcurt, 2020-11-15 16:41:06

How to place a telegram bot on a local host and run it?

I am creating a telegram bot for practice. Created a php file and would like to run. But I do not want to spend on paid hosting and would like to run everything on my PC. The bot will be used by a maximum of 3 people.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
Gleb Starkov, 2020-11-23
@Radia

ngrok

O
Oleg, 2020-11-15
@402d

Getting updates
There are two mutually exclusive ways of receiving updates for your bot - the getUpdates method on one hand and Webhooks on the other. Incoming updates are stored on the server until the bot receives them either way, but they will not be kept longer than 24 hours.
Regardless of which option you choose, you will receive JSON-serialized Update objects as a result.
HTTPS hosting on dynamic ip? So, the only option left is to receive the messages that have come to the bot and send responses using the cron.
In general, there are enough disadvantages to pay money for hosting and not suffer.
But if you still decide to work through
https://tlgrm.ru/docs/bots/api#getupdates
, then pay attention to the 3rd parameter (timeout).
You can cross launch by cron and the correct calculation of this parameter.
As a result, it will respond instantly and end the script at 58-59 seconds.
First you enter 58 seconds.
for example, at 25 seconds the answer came.
processed . sent a reply. looked at how much time had passed from the launch of the script,
requested again with a timeout of 58-passed_seconds.
if the time has come to an end, then complete the script.
Run again the next minute by cron

B
BasiC2k, 2020-11-15
@BasiC2k

There are no difficulties, you launch the bot and check once (for example) per second whether there are messages. Processing and sending a response.

H
hesy, 2020-11-16
@hesy

long poll?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question