Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perl Meets SlackRTM

Shoichi Kaji
March 30, 2016
17

Perl Meets SlackRTM

Gotanda.pm Perl Technology Conference #8 2016.03.30
(original https://www.slideshare.net/skaji/perl-meets-slackrtm)

Shoichi Kaji

March 30, 2016
Tweet

Transcript

  1. SlackRTM • RTM = Real Time Messaging API • A

    websocket-based API that allows you to receive events (message, user_change, …)
 from Slack in real time • You can write BOTs as much as you want
  2. • There already exist awesome cpan modules • AnyEvent::SlackRTM by

    HANENKAMP • AnySan::Provider::Slack by SHOGO
  3. Why mojo? • Yes, Mojo is a web application framework.

    But it can be also a framework for event-driven programing • Has non-blocking http/websocket clients, and event loops • JSON everywhere • websocket has “json” event • http request/response treats json specially • Supports JSON Pointer notation
  4. Eg use Mojo::SlackRTM; my $slack = Mojo::SlackRTM->new(token => $ENV{TOKEN}); $slack->on(message

    => sub { my ($slack, $event) = @_; my $channel_id = $event->{channel}; my $user_id = $event->{user}; my $user_name = $slack->find_user_name($user_id); $slack->send_message($channel_id => "hello $user_name!"); }); $slack->start;
  5. Conclusion • SlackRTM is a websocket-based real time messaging API

    • Perl ❤ SlackRTM with AnyEvent::SlackRTM, AnySan::Provider::Slack, Mojo::SlackRTM • Mojo is a framework not only for web but also for event-driven programming