Exemplo n.º 1
0
 public function connectUserByCode($code, $chat_id)
 {
     $user_id = $this->verify->checkCode($code);
     if ($user_id) {
         $data = $this->readDataFile();
         $data[$user_id] = $chat_id;
         $this->writeDataFile($data);
         return $this->telegram->sendWebhookMessage('Вы успешно подключили функцию уведомления', $chat_id);
     } else {
         return $this->telegram->sendWebhookMessage('Неверный код', $chat_id);
     }
 }
Exemplo n.º 2
0
 /**
  * @return string
  */
 public function getPath()
 {
     if ($this->path == null) {
         $this->path = Telegram::filePath(Telegram::api('getFile', ['file_id' => $this->file_id])['result']['file_path']);
     }
     return $this->path;
 }
Exemplo n.º 3
0
 public function createAndSendRadarGIF($radar_code, $image_radius_code)
 {
     $radar_string = BoM::getBoMRadarString($radar_code, $image_radius_code);
     $web_image_paths = BoM::getRadarTransparencies($radar_code, $image_radius_code);
     $file_path = self::getNewLocalFilePath($web_image_paths);
     if (count($web_image_paths) < 2) {
         \GroupBot\Telegram::talk($this->chat_id, emoji(0x274c) . " Something went wrong getting the radar images fam. The radar might be down. Check here to see if it's working: \n \nhttp://www.bom.gov.au/products/" . $radar_string . ".loop.shtml#skip");
         return false;
     }
     if (!$this->telegram->sendIfExists($file_path)) {
         \GroupBot\Telegram::sendChatSendingPhotoStatus($this->chat_id);
         ImageProcessing::createBackground($radar_string);
         $images = ImageProcessing::overlay($web_image_paths, $radar_string);
         ImageProcessing::animate($images, $file_path);
         $this->telegram->sendGIFThroughTelegram($file_path);
     }
     return true;
 }
Exemplo n.º 4
0
<?php

/**
 * Telegram Cowsay Bot Example.
 * Add @cowmooobot to try it!
 * @author Gabriele Grillo <*****@*****.**>
 */
include "Telegram.php";
// Set the bot TOKEN
$bot_id = "bot_token";
// Instances the class
$telegram = new Telegram($bot_id);
/* If you need to manually take some parameters
*  $result = $telegram->getData();
*  $text = $result["message"] ["text"];
*  $chat_id = $result["message"] ["chat"]["id"];
*/
// Take text and chat_id from the message
$text = $telegram->Text();
$chat_id = $telegram->ChatID();
if ($text == "/start") {
    $option = array(array("🐮"), array("Git", "Credit"));
    // Create a permanent custom keyboard
    $keyb = $telegram->buildKeyBoard($option, $onetime = false);
    $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Welcome to CowBot 🐮 \nPlease type /cowsay or click the Cow button !");
    $telegram->sendMessage($content);
}
if ($text == "/cowsay" || $text == "🐮") {
    $randstring = rand() . sha1(time());
    $cowurl = "http://bangame.altervista.org/cowsay/fortune_image_w.php?preview=" . $randstring;
    $content = array('chat_id' => $chat_id, 'text' => $cowurl);
Exemplo n.º 5
0
<?php

/**
 * Telegram Bot example.
 * @author Gabriele Grillo <*****@*****.**>
 */
include "Telegram.php";
// Set the bot TOKEN
$bot_id = "bot_token";
// Instances the class
$telegram = new Telegram($bot_id);
/* If you need to manually take some parameters
*  $result = $telegram->getData();
*  $text = $result["message"] ["text"];
*  $chat_id = $result["message"] ["chat"]["id"];
*/
// Take text and chat_id from the message
$text = $telegram->Text();
$chat_id = $telegram->ChatID();
// Check if the text is a command
if (!is_null($text) && !is_null($chat_id)) {
    if ($text == "/test") {
        if ($telegram->messageFromGroup()) {
            $reply = "Chat Group";
        } else {
            $reply = "Private Chat";
        }
        // Create option for the custom keyboard. Array of array string
        $option = array(array("A", "B"), array("C", "D"));
        // Get the keyboard
        $keyb = $telegram->buildKeyBoard($option);
Exemplo n.º 6
0
<?php

/**
 * Telegram Bot example.
 * @author Gabriele Grillo <*****@*****.**>
 */
include "Telegram.php";
// Set the bot TOKEN
$bot_id = "bot_token";
// Instances the class
$telegram = new Telegram($bot_id);
/* If you need to manually take some parameters
*  $result = $telegram->getData();
*  $text = $result["message"] ["text"];
*  $chat_id = $result["message"] ["chat"]["id"];
*/
// Take text and chat_id from the message
$text = $telegram->Text();
$chat_id = $telegram->ChatID();
// Check if the text is a command
if ($text == "/test") {
    if ($telegram->messageFromGroup()) {
        $reply = "Chat Group";
    } else {
        $reply = "Private Chat";
    }
    // Create option for the custom keyboard. Array of array string
    $option = array(array("A", "B"), array("C", "D"));
    // Get the keyboard
    $keyb = $telegram->buildKeyBoard($option);
    $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => $reply);
Exemplo n.º 7
0
<?php

ob_start();
header("Content-Type: application/json");
if (!file_exists("config.php")) {
    die("Please copy config.php-example to config.php and insert your API-Key into it.");
}
require_once "config.php";
require_once "Telegram.class.php";
if (API_KEY == "") {
    die("Please define your API-Key.");
}
global $tg;
$tg = new Telegram(API_KEY);
$availableCommands = ["help", "shorturl", "weather", "bot", "encode", "dns", "mac", "ping", "stats", "traceroute", "permission"];
$commandAlias = ["man" => "help", "l" => "shorturl", "dig" => "dns", "trace" => "traceroute"];
if ($tg->getText() == "debuginfo") {
    $tg->sendMessage(file_get_contents('php://input'));
}
// Request from Telegram-Webhooks
if (isset($_GET["t"]) && $_GET["t"] == "webhook") {
    // Check if message was a command
    if (strpos($tg->getText(), "/") === 0) {
        $command = strtolower(ltrim($tg->getCommand()["command"], "/"));
        if (isset($commandAlias[$command])) {
            $command = $commandAlias[$command];
        }
        if (in_array($command, $availableCommands)) {
            include_once "commands/" . $command . ".php";
        }
    } else {
Exemplo n.º 8
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get("/sethook", function () {
    Telegram::setWebhook('https://cantareirabot.herokuapp.com/webhook');
});
Route::any('/webhook', function () {
    $updates = Telegram::commandsHandler(true);
});
 private function sendTelegramMessage($transaction)
 {
     $response = \Telegram::sendMessage(['chat_id' => env('CHAT_ID'), 'text' => $this->createMessage($transaction)]);
 }
Exemplo n.º 10
0
#!/usr/bin/php
<?php 
//previsto da chiamare solo php start.php con 1 eventuale parametro che può essere
//hookset per settare il link di webhook
//hookremove per rimuovere il link di webhook
//getupdates per eseguzione a polling (con cron o manualmente)
//e non si imposta il primo paramentro da shell si assume di avere impostato il webhook e di utilizzare quello
include 'settings_t.php';
include 'getUpdates.php';
//istanzia oggetto Telegram
$bot_id = TELEGRAM_BOT;
$bot = new Telegram($bot_id);
//valuta se l'interfaccia è di tipo CLI per vedere il parametro e settare o rimuovere il webhook e poi esce (se lanciato da riga di comando)
if (php_sapi_name() == 'cli') {
    if ($argv[1] == 'sethook') {
        //setta il webhook
        $bot->setWebhook(BOT_WEBHOOK);
    } else {
        if ($argv[1] == 'removehook') {
            //rimuove il webhook
            $bot->removeWebhook();
        } else {
            if ($argv[1] == 'getupdates') {
                //esegue il getupdates manuale
                getUpdates($bot);
            }
        }
    }
    exit;
}
//legge
Exemplo n.º 11
0
<?php

// This is the Beer Bot, which reads data from the MySQL DB and sends it to
// Telegram users.
// 01.02.2016 / Hannes Badertscher
include "TelegramBotPHP/Telegram.php";
$base = dirname(dirname(__FILE__));
include $base . '/settings/db_settings.php';
include $base . '/settings/bierbot_id.php';
// Setup chat
$telegram = new Telegram($bot_id);
$chat_id = $telegram->ChatID();
// Parse command and arguments
$rawstr = $telegram->Text();
preg_match("/\\/[^\\s\\z\$]*/", $rawstr, $cmd);
$cmd = array_values($cmd)[0];
$args = preg_split("/\\/[^\\s\\z\$]*/", $rawstr);
$args = strtolower(trim(implode(" ", $args)));
// Get sender info
$vorname = $telegram->FirstName();
$nachname = $telegram->LastName();
$username = $telegram->UserName();
switch ($cmd) {
    case "/start":
    case "/start@BierAktionBot":
    case "/help":
    case "/help@BierAktionBot":
        $content = array('chat_id' => $chat_id, 'text' => "Hello. I am BierAktionBot. I try to help you find good beers at cheap prices in Switzerland." . "Type /getBeers to get a list of all beers which are discounted at the moment.");
        $telegram->sendMessage($content);
        break;
    case "/getbeers":
Exemplo n.º 12
0
<?php

/**
 * Telegram Bot Example whitout WebHook.
 * It uses getUpdates Telegram's API.
 * @author Gabriele Grillo <*****@*****.**>
 */
include "Telegram.php";
$bot_id = "bot_token";
$telegram = new Telegram($bot_id);
// Get all the new updates and set the new correct update_id
$req = $telegram->getUpdates();
for ($i = 0; $i < $telegram->UpdateCount(); $i++) {
    // You NEED to call serveUpdate before accessing the values of message in Telegram Class
    $telegram->serveUpdate($i);
    $text = $telegram->Text();
    $chat_id = $telegram->ChatID();
    if ($text == "/start") {
        $reply = "Working";
        $content = array('chat_id' => $chat_id, 'text' => $reply);
        $telegram->sendMessage($content);
    }
    if ($text == "/test") {
        if ($telegram->messageFromGroup()) {
            $reply = "Chat Group";
        } else {
            $reply = "Private Chat";
        }
        // Create option for the custom keyboard. Array of array string
        $option = array(array("A", "B"), array("C", "D"));
        // Get the keyboard
Exemplo n.º 13
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/*
Route::get('/', array(
  'as' => 'test',
  'uses' => 'Humiditybot\TelegramController@test'
));
*/
Route::get('/', function () {
    return View::make('humiditybot.start');
});
Route::post('/updates/{token}', array('as' => 'telegram_updates_get', 'uses' => 'TelegramController@getUpdates'));
Route::get('login', array('as' => 'webapp_login', 'uses' => 'LoginController@showLogin'));
Route::group(array('prefix' => 'api'), function () {
    Route::post('/values/create', array('as' => 'api_values_create', 'uses' => 'ParticleController@createValues'));
    Route::post('/127332203:AAFaKvyjmyxJ-WqQKaCNudBBaxd2PZK39QA/webhook', function () {
        Log::info('Received update', ['update' => Input::all()]);
        Telegram::commandsHandler(true);
        return 'ok';
    });
});
Exemplo n.º 14
0
// Published under the MIT License, Copyright (c) 2015 Pius Ladenburger
/* Telegram Bot Info */
define('TOKEN', 'TOKE_RECEIVED_FROM_TELEGRAM');
define('NAME', 'BOT_NAME');
define('MAX_CALLS', 7);
// maximum calls per hour
/* MySQL Database Info */
define('MYSQL_HOST', 'localhost');
define('MYSQL_USER', 'USERNAME');
define('MYSQL_PASSWORD', 'PASSWORD');
define('MYSQL_NAME', 'BOT');
require './advanced/class.DB.php';
require './advanced/class.session.php';
require './class.telegram.php';
$bot = new Telegram(TOKEN, NAME);
// $DB = new \System\Database\MySQL(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_NAME);
// Incoming update
$request = json_decode(file_get_contents('php://input'), true);
if ($request['update_id']) {
    // Message received
    // BOT CODE HERE
    // API: https://core.telegram.org/bots/api#getting-updates
}
if ($_GET['setHook']) {
    // uncomment, type in your webhook domain and visit example.com/path/to/bot/?setHook=1 to register the hook
    echo $bot->setWebhook('https://example.com/telegram_bot');
} else {
    // uncomment if you need some troubleshooting
    // include ('./advanced/debug.php');
}