M
M
Maksim Borisov2017-09-26 10:58:55
Microsoft Access
Maksim Borisov, 2017-09-26 10:58:55

How to get response from Telegram Bot by condition from Access?

Good day, colleagues! I (unfortunately) am not familiar with PHP and I can’t write a script right off the bat. In corporate needs, I was given the difficult task of writing a Telegram Bot. Puffing, pushing, but it comes out quite crooked. For the first time in my life I decided to write to the forum.
The bottom line is this: can someone say how, according to the condition (we write the car number to the bot), receive the bot's response from Access (the bot gives out its location by the entered car number). There is a database with wagon numbers and the corresponding location.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2017-09-26
@glebovgin

Good afternoon.
1. Be sure to read the documentation https://core.telegram.org/bots/api Without it, nowhere.
2. Here is a super simple php bot

<?php
$botToken = 'ВАШ_ТОКЕН';
$website = 'https://api.telegram.org/bot' . $botToken;

$content = file_get_contents('php://input');
$update = json_decode($content, TRUE);
$message = $update['message'];

$chat_id = $message['chat']['id'];
$text = $message['text'];

$callback_query = $update['callback_query'];
$cq_data = $callback_query['data'];
$message_id = $callback_query['message']['message_id'];
$chat_id_in = $callback_query['message']['chat']['id'];

$params = array();
$params['chat_id'] = $chat_id;
$params['disable_web_page_preview'] = true;

if ($text === '/start') 
{
  $out_message = 'Привет' . (isset($message['from']['username']) ? ', ' . $message['from']['username'] : '' ) . '!
           Я очень полезный бот.';
} elseif($text === '/command1') 
{
  $out_message = 'Ответ на вторую команду вот такой';
} elseif($text === '/command2') 
{
  $out_message = 'Я получил от вас команду 2';
} else 
{
  $out_message = 'Эта команда мне пока что непонятна.';
}

if(isset($out_message))
{
  $params['text'] = $out_message;
  $params['parse_mode'] = 'HTML';
  send($website, '/sendMessage', $params);
}

function send($website, $method = '/sendMessage', $params)
{
  $ch = curl_init($website . $method);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $result = curl_exec($ch);
  curl_close($ch);
}

I advise you to consider this code only as a training one. For a combat bot, a lot of things need to be added and changed. And yes, I deliberately removed the work with CallbackQuery from the code, but left the variables for this at the top.
It is up to you to add this code to your needs. Read the documentation and experiment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question