Example #1
0
<?php

$token = getenv('TELEGRAM_BOT_TOKEN');
if (empty($token)) {
    die('No token');
}
require 'src/bootstrap.php';
use Telegram\Bot\Api;
use WeightLog\WeightLog;
use WeightLog\Db;
$db = Db::getInstance();
$telegram = new Api($token);
$weightLog = new WeightLog($db);
$telegram->addCommand(\WeightLog\TelegramCommands\OutputCommand::class);
$telegram->addCommand(\WeightLog\TelegramCommands\ApiCommand::class);
$telegram->addCommand(\WeightLog\TelegramCommands\HelpCommand::class);
$run = true;
$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);
Example #2
0
require_once 'EDITME/config.php';
require_once 'boot.php';
use Telegram\Bot\Api;
$telegram = new Api($BOTTOKEN);
$updates = $telegram->getWebhookUpdates();
$arup = json_decode($updates, true);
//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']);
Example #3
0
File: midna.php Project: e0th/Midna
<?php

namespace Midna;

use RedBeanPHP\R;
use Telegram\Bot\Api;
require_once __DIR__ . '/../../vendor/autoload.php';
define('MIDNA_TOKEN', 'xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('MIDNA_HOOK', 'https://example.com/path/to/this/file.php');
define('MIDNA_CERT', '/path/to/your/ssl/certificate.pem');
$telegram = new Api(MIDNA_TOKEN);
R::setup('sqlite:' . __DIR__ . '/../../database/database.db');
$telegram->addCommand(new Commands\Start());
$telegram->addCommand(new Commands\Help());
$telegram->commandsHandler(true);
if (php_sapi_name() == 'cli') {
    if ($argv[1] == 'start') {
        print "Starting Midna" . PHP_EOL;
        $bean = R::dispense('messages');
        $bean->message_id = 0;
        $bean->message_date = 0;
        R::store($bean);
        $telegram->setWebhook(['url' => MIDNA_HOOK, 'certificate' => MIDNA_CERT]);
    } else {
        if ($argv[1] == 'stop') {
            print "Stopping Midna" . PHP_EOL;
            $telegram->removeWebhook();
        }
    }
    exit;
}