Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • - sendtoslack - now on SSC: Send message to your smartphone from Stata

    Those who attended the UK User Group Meeting 2017 have already seen the teaser but now -sendtoslack- is also available on SSC (thanks as always to Kit Baum). What is sendtoslack? Despite its cryptic name (to most), it's very simple. This command lets you send custom notifications to your smartphone from Stata, requiring only minimal setup.

    How does it work? Well, that's where the name comes from. Your message actually takes a bit of a detour before reaching your phone. First, the message is sent to Slack, an increasingly popular and highly powerful communications platform (it's free too). Then, once you install the Slack app on your smartphone, it will beep up and show this message right in front of you (assuming your phone is in front of you). The help file takes you step-by-step through the process of setting it up - you don't even technically need to create a Slack account (but please do).

    Note that there's an almost unlimited number of uses for this, but the main ones will probably be the following:
    1. This command can tell you when your hours/days long dofile has finished running.
    2. It can even tell you what the results were, or any other information that can be transmitted in plain text.
    3. You can also use it to inform your colleagues that your part of the process is done (e.g. they may be waiting for the price check to finish).
    4. You can even use it as a reminder - e.g. once the dofile is finished, tell yourself to compare the results to previous estimates. Or send an email to your boss telling him you're finally ready to take over the world.
    5. Always forget your wife's birthday? By messing around with profile.do you could have Stata send her a happy birthday wish on Slack automatically. Or you know, send yourself a message that you should remember to surprise her with something fun.
    As you can see, the possibilities are endless. Unfortunately, at this stage only Windows (8+) users are safeguarded from their wife's scorn as I've only coded the Windows version of this command. However, expanding the code to MAC and Linux is absolutely trivial, I just need someone who actually uses those systems to test the syntax. Even better, this program might already work on MAC if you use the curl option, but I haven't been able to test it.

    Here's some examples (copied straight from the help file) of the syntax
    Code:
    * 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 (explicitly enter URL)
        sendtoslack, url(https://hooks.slack.com/services/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) message("Regression one has been completed.")
    
    * Use build
    ** Store a url in profile.do
        sendtoslack, build(https://hooks.slack.com/services/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)
    
    ** Send custom message to stored url
        sendtoslack, message("Regression one has been completed.")
    
    * Send a message to someone else (me)
        sendtoslack, url(https://hooks.slack.com/services/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) m(This program is the best!)
    And in case you're wondering, this is what it looks like on a smartphone. phoneExample.png

    If you have any questions, please shoot! This is the first version, so some bugs are bound to happen. Finally, this command was inspired by -statapush- which uses the same methodology, but different apps (pushbullet, pushover and ifttt). I find slack more convenient though.

    In future versions, it might be possible to send files to Slack, it's just a bit more involved.
    Last edited by Jesse Wursten; 14 Sep 2017, 07:03.

  • #2
    Thanks to Kit Baum, an updated version of sendtoslack is now available on SSC. The biggest change is that the "build" option has been replaced by "saveurlas" (save url as). This is (imo) a quite nifty way to make sendtoslack 10x more easy to use, especially when working in multiple environments. So how does it work?

    Say you have two channels you want to send output to - one called webhooks and one called general. With the old build option that was tricky. With the new saveurlas option, it's a piece of cake.

    Code:
    * Save urls (using the https://statamessage.slack.com/ slack workspace)
    sendtoslack, saveurlas(webhooks) url(https://hooks.slack.com/services/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)
    sendtoslack, saveurlas(general) url(https://hooks.slack.com/services/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)
    
    * Use them
    sendtoslack, url(general) m(very important message)
    sendtoslack, url(webhooks) m(very important message in webhooks)
    If you're like me, you might still consider this too much effort. Let's pretend you almost always want to send things to the webhooks channel and only infrequently to general. Then you can define the webhooks channel as your default channel, allowing you to omit the url definition in its entirety (is that a word?).

    Code:
    * Save webhooks channel as default url
    sendtoslack, saveurlas(default) url(https://hooks.slack.com/services/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)
    
    * Use it
    sendtoslack, m(very important message sent to the default channel)
    See the help file of sendtoslack to figure out how to get the links (and let me know if you need help).

    Sending files to slack is still in the "future versions" stage, although I've managed to get it to work in a highly controlled environment, so it should still arrive before nuclear fusion powers our homes. Another exciting venue is integration with my upcoming "dom" command, which stands for "do more". There, I've managed to get Stata to send me a message on my smartphone whenever the dofile terminates with an error.

    Comment


    • #3
      I doubt that I really need this, but I want to try it anyway! It sounds really cool, and the idea for doing something like this would have never occurred to me. Thanks for writing it.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Originally posted by Richard Williams View Post
        I doubt that I really need this, but I want to try it anyway! It sounds really cool, and the idea for doing something like this would have never occurred to me. Thanks for writing it.
        Personally, I've found it to be like smartphones themselves - at first I thought it'd just be a bit of fun, but now I'm using it in almost all my projects. E.g. when the data cleaning of a survey we're administrating moves to a next level, everyone on the team automatically gets a notification. Or when my matching procedure finishes running after 26 hours, I also get an update (no more endlessly checking the remote desktop). Still need to set it up so I get a notification for my girlfriend's birthday though...
        Last edited by Jesse Wursten; 05 Dec 2017, 07:30.

        Comment


        • #5
          An updated version of sendtoslack was placed on ssc (thanks to Kit Baum, as always). The newer version makes it easier to integrate sendtoslack (sts for friends) in user-written programs. The help file now contains instructions on how to do this (it's really simple) and a programmer option to shift the sts output horizontally has been added. Overall, the output produced by sts has been cleaned up a bit to be more in line with Stata style.

          Any feedback, suggestions or comments otherwise are very much welcome.

          Comment


          • #6
            The codes in the original post to send a message to the webhooks channel no longer work as someone removed the general webhook. I have set up a new integration, the correct codes are now listed below.

            Code:
            * 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)
            Now also lists the new saveurlas syntax. The new version on SSC has an updated help file to reflect the new webhooks URL.

            Comment


            • #7
              This is amazing, especially when running some tough job remotely, like on a server. I was doing some big data analysis recently on a server. When I begin running the program, I will disconnect from the server and do some regular work. There is no way for me to know if there are some errors when the server was doing the dirty job unless I logging onto the server again. I have not research further on this command, but have you tested the functionality on stata in a server?

              Comment


              • #8
                Originally posted by Noe Zhou View Post
                This is amazing, especially when running some tough job remotely, like on a server. I was doing some big data analysis recently on a server. When I begin running the program, I will disconnect from the server and do some regular work. There is no way for me to know if there are some errors when the server was doing the dirty job unless I logging onto the server again. I have not research further on this command, but have you tested the functionality on stata in a server?
                Hi, as long as the server has internet connectivity and a sufficiently recent version of windows server it should work. If it's a linux server, there's also a way to make it work but I haven't been able to test that myself.

                I have attached an unpublished program I'm working on, currently called cdo.

                Code:
                cdo <dofile>, url(https://hooks.slack.com/services/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)
                Once you have executed cdo.do (to define the cdo program), the code above should start your dofile <dofile> and send you a message on slack (in this case the webhooks channel) if something goes wrong or when the dofile finished execution.
                Attached Files

                Comment


                • #9
                  Originally posted by Jesse Wursten View Post

                  Hi, as long as the server has internet connectivity and a sufficiently recent version of windows server it should work. If it's a linux server, there's also a way to make it work but I haven't been able to test that myself.

                  I have attached an unpublished program I'm working on, currently called cdo.

                  Code:
                  cdo <dofile>, url(https://hooks.slack.com/services/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)
                  Once you have executed cdo.do (to define the cdo program), the code above should start your dofile <dofile> and send you a message on slack (in this case the webhooks channel) if something goes wrong or when the dofile finished execution.
                  Thanks

                  Comment


                  • #10
                    Slack decided to unilaterally kill all example webhooks because someone posted them on Github. If you were using those, update sendtoslack to get the new links in the help file. You may need to update your saved urls. This also applies to cdo and stop.

                    Comment


                    • #11
                      Slack killed the example webhooks again. The program still works, just not the examples in the help file. I'm trying to find a solution.

                      Comment


                      • #12
                        Thanks to ezra goldstein for testing this on linux. It seems to work as long as you specify the -curl- option (and have curl installed).

                        Comment


                        • #13
                          Is this still working? Or does one need to make code changes

                          Comment


                          • #14
                            The stata command still works, but they changed how to generate the webhook URL (haven't had time to look into it myself)

                            Comment

                            Working...
                            X