コード例 #1
0
ファイル: BotController.php プロジェクト: jmramos02/roamio
 public function getUpdates()
 {
     $telegram = new Telegram('112595027:AAHGhHF4_Bj5JiDYHEA-txtUaqe5JZXKnoY');
     $updates = $telegram->getUpdates();
     $last = $updates[count($updates) - 1]["message"]["text"];
     return var_dump($last);
 }
コード例 #2
0
 /**
  * Initialize Telegram Bot SDK Library with Default Config.
  */
 public function registerTelegram()
 {
     $this->app->singleton('telegram', function ($app) {
         $config = $app['config'];
         $telegram = new Telegram($config->get('telegram.bot_token', false), $config->get('telegram.async_requests', false), $config->get('telegram.http_client_handler', null));
         // Register Commands
         $telegram->addCommands($config->get('telegram.commands', []));
         return $telegram;
     });
 }
コード例 #3
0
ファイル: BotCommand.php プロジェクト: jmramos02/roamio
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $haha = 0;
     // while(true) {
     $telegram = new Telegram('112595027:AAHGhHF4_Bj5JiDYHEA-txtUaqe5JZXKnoY');
     $updates = $telegram->getUpdates();
     $message_id = $updates[count($updates) - 1]["message"]["message_id"];
     $text = $updates[count($updates) - 1]["message"]["text"];
     $indb = BeastResponse::orderBy('id', 'desc')->first();
     $queryField = '';
     $nextResponse = '';
     $nextCategory = '';
     //new input
     if ($message_id != $indb->description) {
         //set latest input to new input
         //traverse categories
         for ($i = 0; $i < count($this->categories) - 1; $i++) {
             $options = $this->categories[$i]['options'];
             for ($j = 0; $j < count($options); $j++) {
                 $option = $options[$j];
                 //matched response
                 if ($option["option"] == $text) {
                     $this->info("Pigay");
                     $nextResponse = $options[$j]['response'];
                     $queryValue = $options[$j]['value'];
                     break;
                 }
             }
             $queryField = $this->categories[$i + 1]['category'];
             $nextResponse .= $this->categories[$i + 1]['nextResponse'];
             $nextCategory = $this->categories[$this->categories[$i + 1]['nextCategory']];
         }
         $keyboard = [];
         $options = $nextCategory["options"];
         for ($i = 0; $i < count($options); ++$i) {
             $keyboard[] = [$options[$i]["option"]];
         }
         $reply_markup = $telegram->replyKeyboardMarkup($keyboard, true, true);
         $response = $telegram->sendMessage('60554451', $nextResponse, false, null, $reply_markup);
         $this->info(var_dump($text));
         $indb->description = $message_id;
         $indb->save();
     }
     //if new input
     //   usleep(1000000);
     //}
 }