sendMessage() public method

$params = [ 'chat_id' => '', 'text' => '', 'parse_mode' => '', 'disable_web_page_preview' => '', 'disable_notification' => '', 'reply_to_message_id' => '', 'reply_markup' => '', ];
public sendMessage ( array $params ) : Message
$params array
return Telegram\Bot\Objects\Message
 /**
  * @param TelegramMessageRequest $request
  *
  * @return JsonResponse
  */
 public function store(TelegramMessageRequest $request)
 {
     $content = ['chat_id' => StaffTelegramGroup::id(), 'text' => sprintf('(%s) %s', App::environment(), $request->text())];
     try {
         $message = $this->telegram->sendMessage($content);
         $this->webUi->successMessage("Sent message `{$message->getMessageId()}` to staff");
     } catch (\Exception $e) {
         $this->webUi->errorMessage(sprintf('Failed to send message to staff: %s (%s)', $e->getMessage(), json_encode($content)));
     }
     return $this->webUi->redirect('telegram.index');
 }
 /**
  * @param string $name
  * @param array $args
  *
  * @return bool
  * @throws DialogException
  */
 public function __call($name, array $args)
 {
     if (count($args) === 0) {
         return false;
     }
     $step = $args[0];
     if (!is_array($step)) {
         throw new DialogException('For string steps method must be defined.');
     }
     // @todo Add logging
     if (isset($step['response'])) {
         $params = ['chat_id' => $this->getChat()->getId(), 'text' => $step['response']];
         if (isset($step['markdown']) && $step['markdown']) {
             $params['parse_mode'] = 'Markdown';
         }
         $this->telegram->sendMessage($params);
     }
     if (!empty($step['jump'])) {
         $this->jump($step['jump']);
     }
     if (isset($step['end']) && $step['end']) {
         $this->end();
     }
     return true;
 }
Example #3
0
//syslog(LOG_INFO, $updates);
$acheck = $arup;
unset($acheck['message']['message_id']);
unset($acheck['message']['from']);
unset($acheck['message']['chat']);
unset($acheck['message']['date']);
foreach ($commands as $command) {
    $command = substr_replace($command, '', 0, 7);
    $command = substr_replace($command, '', -4);
    $telegram->addCommand('Commands\\' . $command);
}
foreach ($acheck['message'] as $vc => $avalue) {
    switch ($vc) {
        case "text":
            if ($arup['message']['text'][0] != "/") {
                $telegram->sendMessage($arup['message']['chat']['id'], $lang['error_command']);
            } else {
                $telegram->commandsHandler(true);
            }
            break;
        case "photo":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_photo']);
            break;
        case "voice":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_voice']);
            break;
        case "audio":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_audio']);
            break;
        case "document":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_document']);
Example #4
0
$lastUpdateId = 0;
while ($run) {
    sleep(1);
    $updates = $telegram->commandsHandler(false);
    if (empty($updates)) {
        continue;
    }
    foreach ($updates as $update) {
        $lastUpdateId = $update['update_id'];
        if (substr(trim($update['message']['text']), 0, 1) == '/') {
            continue;
        }
        $weightGiven = preg_replace('/[^0-9\\.]/', '', $update['message']['text']);
        $person = $weightLog->getPersonFromUpdate($update);
        $lastWeight = $person['currentweight'];
        if (empty($weightGiven)) {
            $message = "Huh? I'm afraid that wasn't a valid weight :(";
        } else {
            $result = $db->perform("INSERT INTO weights (timestamp, weight, personid) VALUES (?, ?, ?)", [time(), $weightGiven, $person['id']]);
            $weightLog->setCurrentWeight($person, $weightGiven);
            if (!empty($lastWeight) && $lastWeight > $weightGiven) {
                $diff = round($lastWeight - $weightGiven, 1);
                $message = "That's been logged for you.  You've lost {$diff} lbs or kgs since last time, that's awesome";
            } else {
                $message = "That's been logged for you.  Keep on keeping on!";
            }
        }
        $message .= "\nYou can view all of your logs here: http://weightlog.ashleyhindle.com/?token=" . urlencode($person['token']);
        $telegram->sendMessage($update['message']['chat']['id'], $message);
    }
}
Example #5
0
<?php

use Telegram\Bot\Api;
require 'vendor/autoload.php';
$telegram = new Api('897587587658:AAFbUUXEbKEPT9Bkjalksdjfklashjdflkjasdklf');
$telegram->sendMessage(['chat_id' => '-43054748', 'text' => print_r(['name' => 'José das Couves', 'email' => '*****@*****.**'], true)]);