-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slackbot.h
87 lines (72 loc) · 2.35 KB
/
Slackbot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef _SLACKBOT_H_
#define _SLACKBOT_H_
#include <WebSocketsClient.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include "UrlParser.h"
// Duration to keep flame on after a monitoring alert (15 minutes)
#define UNHEALTHY_DURATION 900000
/**
* @brief
* @remark Code adapted from https://github.com/alexcorvis84/SlackBot/
*
*/
class Slackbot
{
public:
static void update();
private:
/**
* @brief Establishes a bot connection to Slack
*
* @return true if the connection was established successfully.
*/
static bool connect();
static bool authorise(Url &url);
/**
* @brief Called on websocket events. Handles connection and incoming Slack messages
*
* @param type type of websocket event
* @param payload payload
* @param length length of payload
*/
static void webSocketEvent(WStype_t type, unsigned char *payload, unsigned long length);
/**
* @brief Processes a Slack message
*
* @param payload JSON payload to process
*/
static void processPayload(char *payload);
/**
* @brief Reads Slack bot configuration from files in flash.
*
* @return whether files could be read
*/
static bool readConfig();
/**
* @brief Identifies whether a @Inferno command has been received from a user.
* @remark This matching is pretty basic, is case-sensitive and requires a single space.
*
* @param text Slack message text
* @param command the command to test
* @return true whether the payload matched the command.
*/
static bool commandReceived(const char *text, const char *command);
/**
* @brief Initialises Slack message properties that are deserialized.
*/
static void initialisePayloadFilters();
/**
* @brief whether the Slackbot is connected to Slack and can send and receive messages.
*/
static bool _connected;
static WebSocketsClient _webSocket;
static char _botId[64];
static char _oauthToken[128];
static WiFiClientSecure _wifiClient;
static StaticJsonDocument<200> _payloadFilter;
static char _authorisationHeader[256];
static const inline char *slackAlertIndicator = "[Alerting]";
static const inline char *dataDogIndicator = "Triggered: ";
};
#endif