nullboundary / ArduinoSlack

Arduino Slack Bot Library for the Esp8266 wifi board.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArduinoSlack

Run a slack bot on your esp8266 wifi hardware. Useful for triggering digital I/O or reading sensors from your slack channel.


Functions

begin

void begin(const char *token,const char *id);

Begin setups the bot with slack token and bot id

connect

bool connect();

Connect connects to slack (handled by begin)

update

void update();

update bot ping and reconnect if needed

replyMsg

void replyMsg(const char *msg);

reply to channel

sendMsg

void sendMsg(const char *channel,const char *msg);

send msg to a channel

hears

void hears(const char *regex, std::function<void()> callback);

parse bot command and response

fails

void fails(const char *failMsg);

setup default message if bot doesn't understand


Example:

  /****************************************************/
void botCommands() {

  //syntax for bot.hears(regex, reponse function). Try it with a C++11 lambda 
  bot.hears("hello|hi|yo|howdy",[](){ 
    bot.replyMsg("hey hey!"); 
  });

  //try a more complex regex and a longer response function
  bot.hears("(get|read).*(a0|sensor|air.*quality)",readAirSensor);
  
  //if the bot doesn't understand (match) reply with a default message
  bot.fails("Sorry I didn't get that.");

}

/****************************************************/
void readAirSensor() {
    int sensorValue = analogRead(A0); //read analog input

    String valueMsg = String("Ok, the current the value is: "); //format the message
    valueMsg = valueMsg + String(sensorValue);

    bot.replyMsg(valueMsg.c_str()); //reply only takes c style strings
}

About

Arduino Slack Bot Library for the Esp8266 wifi board.


Languages

Language:C 63.1%Language:C++ 36.9%