connect() public méthode

Connects to the real-time messaging server.
public connect ( ) : React\Promise\PromiseInterface
Résultat React\Promise\PromiseInterface
Exemple #1
0
 public function connect()
 {
     return parent::connect()->then(function () {
         return $this->getAuthedUser()->then(function (User $user) {
             $this->pingu = $user;
         });
     });
 }
Exemple #2
0
 /**
  * Connect to slack server
  */
 protected function connect()
 {
     $this->client->connect()->then(function () {
         return $this->client->getAuthedUser();
     })->then(function (User $user) {
         $this->botUser = $user;
         $this->logger->info("Connected as " . $this->botUser->getUsername());
     });
 }
Exemple #3
0
 public function run()
 {
     /*
      * Create the event loop
      */
     $eventLoop = Factory::create();
     /*
      * Create our Slack client
      */
     $client = new RealTimeClient($eventLoop);
     $client->setToken(getenv('BOT_TOKEN'));
     /*
      * Setup command bindings
      */
     $commandBindings = ['help' => HelpCommand::class, 'start' => StartCommand::class, 'end' => EndCommand::class, 'see' => SeeCommand::class, 'vote' => VoteCommand::class, 'kill' => KillCommand::class, 'guard' => GuardCommand::class];
     /*
      * Create the game manager
      */
     $gameManager = new GameManager($client, $commandBindings);
     /*
      * Route incoming Slack messages
      */
     $client->on('message', function ($data) use($client, $gameManager) {
         $gameManager->input(new Message($data));
     });
     /*
      * Connect to Slack
      */
     echo "Connecting...\r\n";
     $client->connect()->then(function () {
         echo "Connected.\n";
     }, function (ConnectionException $e) {
         echo $e->getMessage();
         exit;
     });
     /*
      * Start the event loop
      */
     $eventLoop->run();
 }
Exemple #4
0
 /**
  * Run the bot process.
  *
  * @return void
  */
 public function run()
 {
     $loop = \React\EventLoop\Factory::create();
     $client = new RealTimeClient($loop);
     $client->setToken($this->token);
     // Respond to RTM messages
     $client->on('message', function ($payload) use($client) {
         // Output debug
         $this->debug('Message received', $payload->getData());
         // Create a message entity from payload
         $message = new Message($client, $payload);
         // Certain message types are blocked
         if (!$message->isValidForReaction()) {
             return;
         }
         // Execute relevant command
         $this->react($message);
     });
     $this->debug('Connecting to RTM socket');
     $client->connect()->then(function () {
         $this->debug('Connected to RTM socket');
     });
     $loop->run();
 }