V
V
Vitaliy445s2021-12-29 16:55:56
Python
Vitaliy445s, 2021-12-29 16:55:56

How to write data to a variable from a GET request?

When they register on the site, the site sends a GET request to the bot

like this
api.telegram.org/botAPI/sendMessage?chat_id=MyId&text=ID_USER=66544456?Prime=3

How in the bot to receive this request every time, and write the message text (from the request) to a variable?

I need the bot to automatically write the data from the request (ID_USER and Prime) into variables and send them to the database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ambal245, 2021-12-31
@ambal245

This data comes to the bot's chat with you, so we can read it and write it anywhere. Something like this would be in php

$data = json_decode(file_get_contents('php://input'), true);
if (array_key_exists("message", $data)) {
     $text = $data['message']['text']; // здесь полученный текст ID_USER=66544456?Prime=3
      // парсим текст $param[0] -  id_user $param[1]- prime
     $param = explode('?', $text);
     // если нужны значения отдельно, то еще раз парсим ID_USER=66544456
     // $user = explode('=', $param[0]);
     // записываем в БД
     $insert = $this->pdo->prepare("INSERT INTO user SET user_id = ?, prime = ?");
     $insert->execute(['$param[0], $param[1]]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question