*! version 1.3.4 22may2020

sendtoslack

sendtoslack -- Stata Module to send notifications from Stata to your smartphone through Slack

Syntax

sendtoslack
[, url(string) message(string) method(string) saveurlas(string)]

Description

Main
url your private slack url (instructions below)

message message you want to send to your slack

method use alternative to powershell (currently only curl)

saveurlas store private slack url in profile.do (instructions at bottom)(read: save url as)

Programmer
col(#) moves all output from sendtoslack # spaces to the right

Remarks

There are three ways to use this command, in increasing usefulness and complication.

Option 1: no Slack account and send to public chatroom

1. Go to https://statamessage.slack.com/
2. Sign in as
statamessage@outlook.com
test123
3. Go to the webhooks channel (you might already be there)(channels are listed at the top left)
[warning: will send your computer's name to the public chatroom]
4. Return to Stata, and execute the sendtoslack command without specifying any options.
5. You should now see the default message in Slack, prefixed by your computer name.

Option 2: create Slack account, send to public chatroom

1. Go to https://join.slack.com/t/statamessage/shared_invite/MjM0NTA0MzQwNzM3LTE1MDQyNjkwODQtZWE2NDliNGI4MQ
2. Enter your e-mail address
3. Follow the instruction to create your slack account (takes less than a minute)
Enter details
Skip inviting team members
Skip or follow the tutorial
Go to the webhooks channel (top left)
4. Return to Stata, and execute the sendtoslack command without specifying any options.
5. You should now see the default message in Slack, prefixed by your computer name.

Option 3: create Slack account, send yourself a private message

1. Go to https://join.slack.com/t/statamessage/shared_invite/MjM0NTA0MzQwNzM3LTE1MDQyNjkwODQtZWE2NDliNGI4MQ
2. Enter your e-mail address
3. Follow the instruction to create your slack account (takes less than a minute)
Enter details
Skip inviting team members
Skip or follow the tutorial
Go to the webhooks channel (top left)
4. Go to https://statamessage.slack.com/apps/new/A0F7XDUAZ-incoming-webhooks
5. In "Post to Channel", select Privately to @(your name) and click "Add Incoming Webhooks integration"
6. Copy the "Webhook URL" (something along the lines of https://hooks.slack.com/services/code1/code2/code3)
7. Return to Stata, and execute sendtoslack, url(paste the url here)
8. You should now see the default message sent to yourself in Slack.

The best thing is that you can now install the Slack app on your smartphone,
login and get a notification the instant your code has finished running
(or get live updates, which can even contain regression results).
You may need to modify the settings of the app to give you instant updates (default is 20 minutes delay).
This can be done by going to Settings - Notifications(Settings) - Start mobile notifications...
From what I've noticed so far, Slack doesn't send you a notification if it is also open in the web browser.

Using saveurlas: Make your life easy by storing the URL in profile.do.

1. Execute sendtoslack, url(<your private url>) saveurlas(<name>)
2a. If you specified the name "default"
You can now use sendtoslack without the url option
2b. If you specified a custom name, say "boss"
You can now use sendtoslack, url(boss) and it will send it to the url you stored

This command has only been tested on Windows. Non-windows users are invited to contact me so we can get it to work for them too. The default version will only work on Windows 8+/Server 2008+.
Those using older versions should install curl and use the method(curl) option. On MACs, specifying method(curl) might work as well.

Examples

* Send default message to #webhooks channel

sendtoslack

* Send default message to #webhooks channel (explicitly enter URL)

sendtoslack, url(https://hooks.slack.com/services/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)

* Send custom message to #webhooks channel (..)

sendtoslack, url(https://hooks.slack.com/services/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) message("Regression one has been completed.")

* Use saveurlas
** Store a url in profile.do (default)

sendtoslack, url(https://hooks.slack.com/services/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) saveurlas(default)

** Send custom message to stored url

sendtoslack, message("Regression one has been completed.")

** Store a url in profile.do (custom)

sendtoslack, url("https://hooks.slack.com/services/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") saveurlas(theAuthor)

* Send a message to someone else (me)

sendtoslack, url("https://hooks.slack.com/services/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") m(This program is the best!)

* Send a message to someone else (me), using the stored url

sendtoslack, url(theAuthor) m(This program is the best!)

Integrating sendtoslack in your own commands

Sendtoslack really shines when it's integrated into other commands, which requires very little effort.

1. Add an option "sts(string)" to your syntax
2. Optionally, allow the user to send a custom message with the option "message(string)"
3. Add one of the following lines to your code
a. if "`sts'" != "" sendtoslack, url(`sts')
b. if "`sts'" != "" sendtoslack, url(`sts') message(`"`message'"')
c. if "`sts'" != "" sendtoslack, url(`sts') message(`"`message'"') col(4)
4. Done!

Users can even use their named urls by specifying that name in sts(), or their stored default by specifying sts(default).
The col(4) option shifts the output from sendtoslack 4 spaces to the right, which might look better in your output. Other integers are of course also possible.
Let me know if you would like to see any other functionality and I will see what's feasible.

Author

Jesse Wursten
Faculty of Economics and Business
KU Leuven
jesse.wursten@kuleuven.be

Inspired by statapush.