1

I'm using a web tool that has inbound webhooks. They provide me with a URL, to which I can POST a string and it logs it into the system.

I would like to create a script that me and my team can use from the terminal to do something like this:

~: appName 
~: What is the webHook URL? 

Here I can copy and paste the URL gives me, and stores it. Then from now I can do this:

~: appName This is a message that I want to send...

And this sends as a POST to the webhook the string. This would ideally something I can share with non-techies and that's easy to set up. And I have no idea how to even start this.

1
  • You can use curl to post to sites, and a bash tutorial for the rest. Commented Apr 1, 2015 at 16:36

2 Answers 2

1

I am assuming you want this to be strictly shell.

In the end you want to use something like curl (bash)

curl --data "msg=$2" $url

The $url variable could come from a flat file(app.txt) that is just key value with key=appName

You first script would need to append to the file(app.txt)

echo $1 $2 >> app.txt
Sign up to request clarification or add additional context in comments.

Comments

1

This is how you can get started:

#!/bin/bash
msg=$1
url=""
[ ! -f webhookurl ] || url=`cat webhookurl` #webhookurl is a file where you put the url
if [ "$url" == "" ]; then
read -p "What is the webHook URL? " url
echo $url > webhookurl
fi

# Now start posting message

curl --data "msg=$msg" $url

save it with appname. Then run appname like this:

./appname "message to send"

It will ask for url for the first time and save it in webhookurl file in the same folder as the script for future use.

3 Comments

Is it possible to have it installed globally? If yes how?
For example, when I do npm install app...,npm works everywhere
Put the script in /usr/bin or /bin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.