E
E
EVG822020-10-08 11:40:12
PHP
EVG82, 2020-10-08 11:40:12

How to implement video transmission along with a message in a telegram bot in php?

Struggling with the task. And I am sure that everything should be simple.
The following has been implemented: when the start command
appears, first a picture appears below it with text and a button below the text. that is, you can see that the text and photo are separate messages.
how to combine it?

Second question.

What code structure conveys the video in the message?

Here is the code that seems to work

header('Content-Type: text/html; charset=utf-8');
// подрубаем API
require_once("vendor/autoload.php");

// создаем переменную бота
$token = "1264639615:AAEAu5owEhNTH4H-hJ4jNg";
$bot = new \TelegramBot\Api\Client($token);

// если бот еще не зарегистрирован - регистрируем
if(!file_exists("registered.trigger")){ 
  /**
   * файл registered.trigger будет создаваться после регистрации бота. 
   * если этого файла нет значит бот не зарегистрирован 
   */
   
  // URl текущей страницы
  $page_url = "https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  $result = $bot->setWebhook($page_url);
  if($result){
    file_put_contents("registered.trigger",time()); // создаем файл дабы прекратить повторные регистрации
  }
}

// Кнопки у сообщений
//================ вызывается команда бота появлется сообщение и под ним кнопка "смотреть видео"============
$bot->command("start", function ($message) use ($bot) {
   	$keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup(
    [
      [
        ['callback_data' => 'data_test', 'text' => 'Смотреть видео 1', 'one_time_keyboard' => true],
        //['callback_data' => 'data_test2', 'text' => 'ОтветЪ']  втоаря кнопка. пока не нужна
      ]
    ]
  );
//	$url = "BAACAgIAAxkBAAICcV9927FlDPwZfFNk3uh2CpB0vMV5AAJUCQACwK5-9mnPhcGwQ";
  $pic = "AgACAgIAAxkBAAICb199ye19M9O6eiEoftEtwXIHwXCUAAIEszEbitzxS4_hUZs9pFpCYq1sli4AAwEABGwQ";
  //$bot->sendVideo($message->getChat()->getId(), $video);
  //$sendVideo = new SendVideo();
    //$sendVideo->chat_id = A_USER_CHAT_ID;
    //$sendVideo->video = new InputFile('/video/1_spasaem_mir.mp4');
    //$sendVideo->caption = 'тут описание видео';
  //$bot->sendVideo([ 'chat_id' => $chat_id, 'video' => $url, 'caption' => "Описание видео" ]);
    $bot->sendPhoto($message->getChat()->getId(), $pic);
    $bot->sendMessage($message->getChat()->getId(), "Здравствуйте, {{first_name}}!  ", false, null,null,$keyboard);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danny Arty, 2020-10-08
@DanArst

the picture appears first under it the text and under the text the button. that is, you can see that the text and photo are separate messages.
how to combine it?

Use the sendPhoto method , and write the text in the caption to it, instead of using sendMessage - then they will be merged.
How to implement video transmission along with a message in php

As in the previous version, only sendVideo is used instead of sendPhoto and, accordingly, a caption to it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question