Ejemplo n.º 1
0
<?php

/**
 * T3Bot.
 *
 * @author Frank Nägler <*****@*****.**>
 *
 * @link http://www.t3bot.de
 * @link http://wiki.typo3.org/T3Bot
 */
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config/config.php';
// The Slack connection
$loop = React\EventLoop\Factory::create();
$client = new Slack\RealTimeClient($loop);
$client->setToken($GLOBALS['config']['slack']['botAuthToken']);
$client->on('message', function (Slack\Payload $payload) use($client) {
    if ($payload->getData()['user'] !== $GLOBALS['config']['slack']['botId']) {
        $commandResolver = new \T3Bot\Slack\CommandResolver($payload, $client);
        $command = $commandResolver->resolveCommand();
        if ($command instanceof \T3Bot\Commands\AbstractCommand) {
            $result = $command->process();
            if ($result !== false) {
                $command->sendResponse($result);
            } else {
                $command->sendResponse($command->getHelp());
            }
        }
    }
});
$client->on('channel_created', function (Slack\Payload $payload) use($client) {
Ejemplo n.º 2
0
<?php

include 'vendor/autoload.php';
date_default_timezone_set('Europe/Moscow');
$logger = new \SlackBot\Logger\EchoLogger();
$invoker = new \SlackBot\Invoker\Invoker();
$invoker->addCommand(new \SlackBot\Command\PingPong($logger));
$loop = React\EventLoop\Factory::create();
$client = new Slack\RealTimeClient($loop);
$client->setToken('SLACK_TOKEN');
$bot = new \SlackBot\Bot($loop, $client, $invoker, $logger);
$bot->run();