TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Usage story (is there a direct GET API for triggering?)

    General Discussion
    2
    9
    2.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by A Former User

      Short form: daisychained Slack bot -> Zapier -> TC Zapier hook -> triggercmd.com -> TC OSX client -> shell script -> SSH command -> shell script -> SQL script.

      Long form:
      I wanted to make a Slack bot to let my team members just type a command to do themselves what they kept asking me to do. But the hoops to get a Slack integration with Jenkins are pretty high where I work, and I wondered if I could make a poor-man's version, instead.

      So:

      1. I could find no local-machine slack bot, but followed the tutorial at https://zapier.com/blog/how-to-build-chat-bot/ to set up a /dbupdate slash command on Slack, and to create a Zapier hook on that.
      2. I then looked around for something to let Zapier run a local command on my laptop, and found TriggerCmd.
      3. Turns out TC has a Zapier integration in testing, so I used that (https://www.triggercmd.com/forum/topic/10/now-you-can-use-zapier-to-trigger-your-commands) - another user towards the 10-user requirement to publish it!
      4. Then I made a command open ~/bin/dbupdate to run my local script. Had a lot of trouble getting it to show up, probably because I was using the manual rather than UI editor, and made some mistake somewhere - I think it was not having the open at the beginning, but why would that make the command silently not appear at all? Or did it need a voice command? Not sure.
      5. That script contains just the command ssh qa_server /home/dmorgan/dbupdate-hook
      6. The dbupdate-hook script it calls on the qa_server contains just /path/to/dbupdatescript.php -m
      7. dbupdatescript.php then does all the DB updating.

      Two of those systems (the TC OSX client, and the TC Zapier integration) aren't widely used, but seem to work perfectly.

      I could get rid of two of the scripts (steps 5 and 6) by having the TC command be ssh qa_server /path/to/dbupdatescript.php -m, but this way lets me add in some logging, and in the future, parameter handling.

      Some questions/comments:

      1. I think I could get rid of the need for Zapier, and use TC directly for communicating with bots, if I could find a way to activate TRIGGERCmd through a single GET request to an API endpoint, rather than a POST request. Is this possible?
      2. I had some trouble getting the command to appear on the TC website, I think because I edited the command manually, and didn't put in the leading open - apparently this is required? Some kind of error display explaining what's broken about your command would be nice, since the local command clearly knows you have the command.
      3. The "background/foreground" option seems pointless on Mac, since it does nothing (not even for the Calculator demo). However the open command (https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/open.1.html) takes a -g option to open the thing in the background, so this isn't a big deal.
      4. It took me forever, on OSX, to figure out that I was meanta click the tiny icon at the top of the screen, rather than the icon in the mac toolbar, in order to do things with the app. By the time I noticed the tiny icon, I'd found the config file, and tried manually editing a command in, and become sad that I could not see the command on the TC website. Maybe (at least for OSX) make that clearer, or hide the big icon. [I see this is addressed in another recent thread :)]
      5. I'm considering adding a parameter, since Zapier parameters are now supported - is there documentation on this, or is it sufficiently straightforward that I can probably just figure it out?
      RussR 1 Reply Last reply Reply Quote 0
      • RussR
        Russ @A Former User
        last edited by Russ

        @dewi-morgan, yes, you can use this format for your GET:

        curl "https://www.triggercmd.com/api/run/triggerSave?computer=russfam&trigger=calculator&token=(token)"
        

        Or with a parameter:

        curl "https://www.triggercmd.com/api/run/triggerSave?computer=russfam&trigger=notepad&token=(token)&params=russ"
        

        Sorry about your trouble getting it working. I think the latest version of the mac client solves some of that.

        You did not need a voice command. I think the trouble was likely some missing backslashes to escape any forward slashes in your command.

        You're correct that there's no use for background commands on a mac because I didn't implement a way to install a daemon on macs. I'll consider getting rid of that background field in the GUI editor in the mac version in a future.

        Also, thanks for using the Zapier integration, and thanks for posting your use case. I like it.

        Russell VanderMey

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User
          last edited by

          I'm not sure it's just missing backslashes.

          But even if missing backslashes for forwardslashes is a thing, then... why? Are they being run through a regex without escaping them or something?

          I added an updatedb-test command, and again it did not appear. To get it working it seemed that I first had to create the script it called, and get it to run successfully locally; or possibly to delete the "visit website" command to there was space for it; . But once I got it to appear, the existing, and previously-working updatedb command disappeared.

          I cannot get it back even by going to the raw editor and adding slashes. In fact, the slashes seem to disappear when I save.

          Having it hard and non-debuggable to get commands to appear is frustrating, but having working commands that I'm not currently editing just disappear on me is even more so.

          So let's try this new version...

          OOH! I like the new install. Smooth 🙂

          Looks like the command is still missing from the website, though. Renaming "updatedbtest" to "updatedbtestx" in the GUI editor shows up immediately on the website, so it's communicating - it's just not showing the "Updatedb" command. Renaming "Updatedb" to "Updatedbx" does not make it appear.

          ~/.TRIGGERcmdData/commands.json contains:

          [
           {
            "trigger": "Calculator",
            "command": "open -g -a Calculator",
            "ground": "background",
            "voice": "calculator"
           },
           {
            "trigger": "Updatedb",
            "command": "open -g ~/bin/updatedb",
            "ground": "background",
            "voice": "updatex",
            "allowParams": "true"
           },
           {
            "trigger": "updatedbtest",
            "command": "open -g ~/bin/updatedbtest",
            "ground": "foreground",
            "voice": "updatedbtestx",
            "allowParams": "true"
           }
          ]
          

          ... looks valid JSON to me. Note there are no backslashes. Using a text editor (vi), I changed this to:

          [
           {
            "trigger": "Calculator",
            "command": "open -g -a Calculator",
            "ground": "background",
            "voice": "calculator"
           },
           {
            "trigger": "xxupdatedbtest",
            "command": "open -g ~\/bin\/updatedbtest",
            "ground": "foreground",
            "voice": "updatedbtestx",
            "allowParams": "true"
           },
           {
            "trigger": "Updatedb",
            "command": "open -g ~\/bin\/updatedb",
            "ground": "background",
            "voice": "updatex",
            "allowParams": "true"
           }
          ]
          

          (swap the bottom two items, add backslashes, rename updatedbtest). On the website I see updatedebtest is renamed, so these changes have been pushed, but still no Updatedb.

          Opening the in-app text editor, I see the backslashes, but not in the GUI editor. Editing the entry for updatedb in the GUI editor, all backslashes are removed from the file.

          I don't think this is a bug: I'd expect the GUI editor to escape anything it felt needed escaping, and it does indeed escape backslashes if I add them (they get turned into a double-backslash). So I suspect it is working correctly. I don't see why forward-slashes would need escaping here, in quoted strings. That's not JSON standard, for sure.

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User
            last edited by

            Did the above help at all with reproduction? If not, is there any other information I can provide or tests I can run?

            As it is, it's unusable for me - a shame, as it otherwise looks likely to save me and the QA team lots of hassle and interruptions each day 😞

            RussR 1 Reply Last reply Reply Quote 0
            • RussR
              Russ @A Former User
              last edited by Russ

              @dewi-morgan, I see the issue.

              Some of our commands are set as "background" commands. The mac client will ignore those entries. If you change them to foreground, they should work fine.

              I didn't implement the background service on the mac client.

              Russell VanderMey

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User
                last edited by A Former User

                I was skeptical, since calculator has always been background, and yet has always shown up in the list, and since Updatedb used to show up, once I set it to background, like I said in my first post.

                But I tried setting all to foreground, and it worked! Thanks 🙂

                RussR 1 Reply Last reply Reply Quote 0
                • RussR
                  Russ @A Former User
                  last edited by

                  Awesome @dewi-morgan.

                  Have you tried the GET API?

                  Just want to confirm that's working for you too.

                  curl "https://www.triggercmd.com/api/run/triggerSave?computer=russfam&trigger=calculator&token=(token)"
                  

                  Russell VanderMey

                  1 Reply Last reply Reply Quote 0
                  • RussR
                    Russ
                    last edited by

                    @Dewi-Morgan, I'd be interested in writing a Slack bot or some sort of integration with Slack. Can I get your ideas on that?

                    Russell VanderMey

                    1 Reply Last reply Reply Quote 0
                    • RussR
                      Russ
                      last edited by Russ

                      @Dewi-Morgan, check this out:

                      https://youtu.be/1yvMMoj1Oxc

                      It's not on the Slack App Directory yet, but you can start using it now.

                      EDIT: It's in the Slack directory now.

                      Russell VanderMey

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post