2017 © Pedro Peláez
 

library twitter-monitor

Twitter Stream monitoring tool

image

howyi/twitter-monitor

Twitter Stream monitoring tool

  • Friday, May 18, 2018
  • by howyi
  • Repository
  • 0 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

twitter-monitor

Twitter Stream monitoring tool, (*1)

Start monitoring

// Return the greeting bot

$monitor = new \ServiceMonitor\Twitter\UserStreamMonitor(
    getenv('TWITTER_ACCESS_TOKEN'),
    getenv('TWITTER_ACCESS_TOKEN_SECRET'),
    getenv('TWITTER_CONSUMER_KEY'),
    getenv('TWITTER_CONSUMER_SECRET')
);

$event = new class extends \ServiceMonitor\Twitter\TwitterEvent
{
    public function isExecutable(array $value): bool
    {
        if (!isset($value['in_reply_to_user_id_str']) or !isset($value['text'])) {
            return false;
        }

        if ($value['in_reply_to_user_id_str'] !== $this->self->id_str) {
            return false;
        }

        return (strpos($value['text'], 'hello') !== false);
    }

    public function execute(array $value): void
    {
        echo("User:@{$value['user']['screen_name']} greeted :)" . PHP_EOL);

        $status = "Hello, @{$value['user']['screen_name']} !";

        $this->connection->post(
            'statuses/update',
            ['in_reply_to_status_id'=> $value['id_str'], 'status' => $status]
        );
    }
};

$monitor->setEvent($event);
$monitor->start();

The Versions