The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Async::Slack::Socket - socket-mode notifications for https://slack.com

DESCRIPTION

This is a basic wrapper for Slack's socket-mode features.

See https://api.slack.com/apis/connections/socket for some background on using this feature.

This provides an event stream using websockets.

For a full list of events, see https://api.slack.com/events.

METHODS

events

This is the stream of events, as a Ryu::Source.

Example usage:

 $rtm->events
     ->filter(type => 'message')
     ->sprintf_methods('> %s', $_->text)
     ->say
     ->await;

handle_unfurl_domain

Registers a handler for URLs.

Takes the following named parameters:

  • domain - which host/domain to respond to, e.g. google.com for https://google.com

  • handler - a callback, expected to take a URI instance and return a Future with a Slack message

Example usage:

 $sock->handle_unfurl_domain(
     domain => 'service.local',
     handler => async sub ($uri) {
         my ($id) = $uri->path =~ m{/id/([0-9]+)}
             or return undef;
         return +{
             blocks => [ {
                 "type" => "section",
                 "text" => {
                     "type" => "mrkdwn",
                     "text" => "Request with ID `$id`",
                 },
             } ]
         };
     }
 );

Returns the Net::Async::Slack::Socket instance to allow chaining.

last_frame_epoch

Returns the floating-point timestamp for the last frame we received. Will be undef if we have no frames yet.

METHODS - Internal

You may not need to call these directly. If I'm wrong and you find yourself having to do that, please complain via the usual channels.

connect

Establishes the connection. Called by the top-level Net::Async::Slack instance.

INHERITED METHODS

IO::Async::Notifier

add_child, adopt_future, adopted_futures, can_event, children, configure_unknown, debug_printf, get_loop, invoke_error, invoke_event, loop, make_event_cb, maybe_invoke_event, maybe_make_event_cb, new, notifier_name, parent, remove_child, remove_from_parent

AUTHOR

Tom Molesworth <TEAM@cpan.org>

LICENSE

Copyright Tom Molesworth 2016-2022. Licensed under the same terms as Perl itself.