3. 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
8. 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
9. 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;
10. 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