Go to the documentation of this file.
26 #ifndef O2SCL_SLACK_MESSENGER_H
27 #define O2SCL_SLACK_MESSENGER_H
29 #ifndef DOXYGEN_NO_O2NS
82 std::string p_url=
"",
bool p_mpi_time=
false) {
84 if (p_url.length()==0) {
99 O2SCL_ERR2(
"Value mpi_time is true but O2SCL_MPI not defined ",
100 "in slack_messenger::slack_messenger().",
115 O2SCL_ERR2(
"Value mpi_time is true but O2SCL_MPI not defined ",
116 "in slack_message::slack_message().",
129 char *cstring=getenv(env_var.c_str());
137 bool set_channel_from_env(std::string env_var) {
138 char *cstring=getenv(env_var.c_str());
149 char *cstring=getenv(env_var.c_str());
159 int send(std::string message,
bool err_on_fail=
true) {
163 if (
url.length()>0) {
177 time_now=MPI_Wtime();
179 O2SCL_ERR2(
"Value mpi_time is true but O2SCL_MPI not defined ",
180 "in slack_message::slack_message().",
190 if (
icon.length()>0) {
191 scr=((std::string)
"curl -X POST --data-urlencode ")+
192 "\"payload={\\\"channel\\\": \\\""+
channel+
"\\\", "+
193 "\\\"username\\\": \\\""+
username+
"\\\", "+
194 "\\\"text\\\": \\\""+message+
"\\\", "+
195 "\\\"icon_emoji\\\": \\\":"+
icon+
":\\\"}\" "+
url;
197 scr=((std::string)
"curl -X POST --data-urlencode ")+
198 "\"payload={\\\"channel\\\": \\\""+
channel+
"\\\", "+
199 "\\\"username\\\": \\\""+
username+
"\\\", "+
200 "\\\"text\\\": \\\""+message+
"\\\"}\" "+
url;
204 std::cout <<
"Executing: " << scr << std::endl;
207 iret=system(scr.c_str());
209 if (iret!=0 && err_on_fail) {
228 #ifndef DOXYGEN_NO_O2NS
std::string username
Slack username.
bool set_url_from_env(std::string env_var)
Set the Slack webhook URL from an environment variable.
@ exc_efailed
generic failure
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Object to send messages to Slack using curl.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
bool mpi_time
If true, use MPI to determine time.
std::string icon
Icon to use (without colons; default "computer")
void set_time_mode(bool loc_mpi_time)
Set the time mode (normal or MPI)
double time_last_message
Time (in seconds) the last message was sent.
double min_time_between
Minimum time between messages in seconds (default 300)
slack_messenger(std::string p_channel="", std::string p_username="", std::string p_url="", bool p_mpi_time=false)
Create a messenger object with specified channel, username, URL and time method.
@ exc_einval
invalid argument supplied by user
std::string url
The URL for the Slack webhook.
int verbose
Verbosity parameter (default 1)
std::string channel
The destination channel.
int send(std::string message, bool err_on_fail=true)
Send a message.
bool set_username_from_env(std::string env_var)
Desc.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).