-
Notifications
You must be signed in to change notification settings - Fork 17
/
00-showcase.cpp
68 lines (53 loc) · 2.25 KB
/
00-showcase.cpp
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
#include "slacking.hpp"
#include <fstream>
#include <iostream>
// Example 3
void more_elaborate_example() {
// https://api.slack.com/messaging/composing/layouts#attachments
auto &slack = slack::instance();
slack.chat.channel_username_iconemoji("#general", "Support Bot", ":hamster:");
auto json_attachments = R"([
{
"fallback": "New ticket from Bjarne Stroustrup - Ticket #2017: Still looking for reflection",
"color": "#7CD197",
"pretext": "New ticket from Bjarne Stroustrup",
"title": "Ticket #2017: Still looking for reflection",
"title_link": "https://www.youtube.com/watch?v=ND-TuW0KIgg",
"text": "Help me adding reflection!",
"image_url": "https://img.youtube.com/vi/ND-TuW0KIgg/2.jpg"
}
])"_json;
slack.chat.attachments = json_attachments; // equivalent to slack::instance().chat_postMessage.attachments = json_attachments.dump();
auto result = slack.chat.postMessage();
}
int main() {
std::cout << "Slacking starting" << std::endl;
auto& slack = slack::create("xxx-xxx"); // where "xxx-xxx" is your Slack API token
slack.set_throw_exception(false); // feel free to disable exception (true by default)
slack.chat.channel = "#general";
slack.chat.postMessage("Hello there!"); // will send the message "Hello there!" in the channel #general
// Example 1
// You can also use the generic post slack approach. Parameters (except the token) will not be taken into account.
// Everything from the Web Slack API is possible here!
slack::post (
"chat.postMessage",
{
{"text" , "Slacking is awesome!" },
{"channel" , "#general" },
{"username" , "peach" },
{"icon_emoji", ":princess:" }
}
);
// Example 2
// You can also use the generic post with a a Json approach.
auto json = R"({
"text": "Slacking is simple!",
"channel" : "#general",
"username": "peach",
"icon_emoji": ":princess:"
})"_json;
slack::post("chat.postMessage", json);
// Example 3
more_elaborate_example();
std::cout << "Slacking example ended normally." << std::endl;
}