Giter VIP home page Giter VIP logo

slack-rtm-bot's Introduction

NAME

Slack::RTM::Bot - This is a perl module helping to create slack bot with Real Time Messaging(RTM) API.

SYNOPSIS

use Slack::RTM::Bot;
my $bot = Slack::RTM::Bot->new( token => '<API token>');

$bot->on({
        channel => 'general',
        text    => qr/.*/
    },
    sub {
        my ($response) = @_;
        print $response->{text}."\n";
    }
);

$bot->start_RTM(sub {

    $bot->say(
        channel => 'general',
        text    => '<!here> hello, world.'
    );

    $bot->say(
        channel => '@username',
        text    => 'hello, world.'
    );

    while(1) { sleep 10; print "I'm not dead\n"; }
});

METHODS

new

method new(token => $token)

Constructs a Slack::RTM::Bot object.

The $token is the slack API token.

on

method on(\%event, $callback)

$callback will be executed when it fitted the \%event conditions. The \%event key is equal to a key of json received from slack, and value is estimated as regex.

$callback is handed JSON object of message received from Slack.

start_RTM

method start_RTM($callback)

It start Real Time Messaging API. $callback will be executed when establish connection. start_RTM make child process. Thus, you must call stop_RTM if you want to kill child processes before stop main process.

stop_RTM

method stop_RTM()

It stop Real Time Messaging API.

say

method say(%options)

It sent a message to a Slack. The channel name can be used to designate channel. if you want to send a direct message, let designate the @username as a channel.

SOURCE CODE

This is opensource software.

https://github.com/duck8823/Slack-RTM-Bot

HOW TO CONTRIBUTE

with installing

The fastest way to get started working with the code is to run the following commands:

$ git clone https://github.com/duck8823/Slack-RTM-Bot.git
$ cd Slack-RTM-Bot
$ cpanm --installdeps .
$ perl Build.PL
$ ./Build
$ ./Build install
$ ./Build test  # run the tests

without installing

or without installing Slack-RTM-Bot, run the following commands:

$ git clone https://github.com/duck8823/Slack-RTM-Bot.git
$ cd Slack-RTM-Bot
$ cpanm --installdeps .  # install dependencies

and run your script with `-I/path/to/Slack-RTM-Bot/lib` option.

$ perl -I/path/to/Slack-RTM-Bot/lib your_script.pl

SEE ALSO

https://api.slack.com/rtm

LICENSE

The MIT License (MIT)

Copyright (c) 2016 Shunsuke Maeda

See LICENSE file.

AUTHOR

Shunsuke Maeda [email protected]

slack-rtm-bot's People

Contributors

dada avatar duck8823 avatar kimjackson avatar makamaka avatar manwar avatar poptix avatar tomascohen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.