Slack Curl



@mattstone-ascot @jlwin it's most certainly not a matter of preference. The PHP Framework Interoperability Group (PHP-FIG), participated in by the maintainers of such insignificant PHP projects as Symfony, Laravel, Yii, Zend, Composer, Drupal, Joomla, Magento, phpBB and CakePHP, has set some universally accepted standards, amongst which the coding standards PSR-1 and PSR-2. Slack improves communication across distributed teams. Out of 200 DevaCurl employees, 125 of them are based in the company’s salons. That means over half of its workers are on their feet, interacting with customers, rather than in front of a computer screen.

Start using packagecloud in minutes

Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un.x-like operating systems. It only takes a minute to sign up. Slack Connect lets two companies move as quickly as one. Hatch a partnership. Build something new. Learn more about Slack Connect. And you can chat face to face, with just a click. And video calling, too. In short: it’s a more human way to work. Any idea if slack can have a command or a bot to execute a curl command against a website/api on the interwebz? Command: /service parameter: abc123. Slack: /service abc123. Where parameter is an argument to append to that curl command.

Join thousands of developers using packagecloud to distribute software securely, consistently, and affordably.

Quick install instructions for:

Other options:

Other options:

Other options:

Other options:

Other options:

Packages

NameDistro/VersionUploaded on
slack-4.15.0-0.1.fc21.x86_64.rpmfedora/21pushed by jho-slack 2 days ago
slack-desktop_4.15.0_amd64.debdebian/jessiepushed by jho-slack 2 days ago
slack-desktop_4.14.0_amd64.debdebian/jessiepushed by jho-slack about 1 month ago
slack-4.14.0-0.1.fc21.x86_64.rpmfedora/21pushed by jho-slack about 1 month ago
slack-4.13.0-0.1.fc21.x86_64.rpmfedora/21pushed by CharlieHess 2 months ago
slack-desktop_4.13.0_amd64.debdebian/jessiepushed by CharlieHess 2 months ago
slack-4.12.2-0.1.fc21.x86_64.rpmfedora/21pushed by devinfoley 3 months ago
slack-desktop_4.12.2_amd64.debdebian/jessiepushed by devinfoley 3 months ago
slack-4.12.1-0.1.fc21.x86_64.rpmfedora/21pushed by devinfoley 4 months ago
slack-desktop_4.12.1_amd64.debdebian/jessiepushed by devinfoley 4 months ago
slack-4.12.0-0.1.fc21.x86_64.rpmfedora/21pushed by CharlieHess 4 months ago
slack-desktop_4.12.0_amd64.debdebian/jessiepushed by CharlieHess 4 months ago
slack-4.11.3-0.1.fc21.x86_64.rpmfedora/21pushed by CharlieHess 5 months ago
slack-desktop_4.11.3_amd64.debdebian/jessiepushed by CharlieHess 5 months ago
slack-4.11.1-0.1.fc21.x86_64.rpmfedora/21pushed by devinfoley 6 months ago
slack-desktop_4.11.1_amd64.debdebian/jessiepushed by devinfoley 6 months ago
slack-desktop_4.11.0_amd64.debdebian/jessiepushed by devinfoley 6 months ago
slack-4.11.0-0.1.fc21.x86_64.rpmfedora/21pushed by devinfoley 6 months ago
slack-desktop_4.10.3_amd64.debdebian/jessiepushed by devinfoley 6 months ago
slack-4.10.3-0.1.fc21.x86_64.rpmfedora/21pushed by devinfoley 6 months ago
slack-4.10.0-0.1.fc21.x86_64.rpmfedora/21pushed by devinfoley 7 months ago
slack-desktop_4.10.0_amd64.debdebian/jessiepushed by devinfoley 7 months ago
slack-4.9.1-0.1.fc21.x86_64.rpmfedora/21pushed by devinfoley 7 months ago
slack-desktop_4.9.1_amd64.debdebian/jessiepushed by devinfoley 7 months ago
slack-desktop_4.8.0_amd64.debdebian/jessiepushed by felixrieseberg 9 months ago
slack-4.8.0-0.1.fc21.x86_64.rpmfedora/21pushed by felixrieseberg 9 months ago
slack-4.7.0-0.1.fc21.x86_64.rpmfedora/21pushed by felixrieseberg 10 months ago
slack-desktop_4.7.0_amd64.debdebian/jessiepushed by felixrieseberg 10 months ago
slack-4.4.3-0.1.fc21.x86_64.rpmfedora/21pushed by felixrieseberg 11 months ago
slack-desktop_4.4.3_amd64.debdebian/jessiepushed by felixrieseberg 11 months ago

This bash script will post a message to Slack. It can be easily changed to fit your needs but it can be used as it is as well. This script is very useful to send notifications for background tasks for example.

This bash script is utelising curl to post a message to a given slack channel. The script expects 4 arguments:

  1. title of the message
  2. message body
  3. Slack channel name
  4. Slack hook url

Having said that there is nothing preventing you from adding extra parameters, for example you can add an emoji as an argument for further customising your messages look and feel.

Usage block

The script starts with a function which returns the usage block. Usage function acts as documentation for the program. This function is called if the user doesn't pass any of the parameters or as a default response if the user just trid to execute the script without passing anything. Listing 1.1 shows the usage function

Mention

Listing 1: usage function

Extracting arguments

Listing 2 shows how I am extracting and validating arguments for this script

Slack Curl Mention

Listing 2: extracting and validating arguments

Minimal validating for arguments is happening here however you can add whatever extra validation that you want. For example you may want to restrict the channel name to be of certain values

Posting the message

The rest of the script is using curl to post the message to Slack.

Note how I am utilising the read command to format the json payload. This technique offers maximum readability and customisation for your message payload. This program output the status code returned from curl. So anything but 200 means failure

Listing 3: posting message to Slack and return status code

If you don't have a bin folder under your home folder then create one and place this script in it. Alternatively you can place this script in /usr/local/bin/code so that it is available for all users

Next you need to make this script executable

Create symbolic link - optional

Slack Curl Invalid Payload

You can create a symlink for this script so you can name it whatever you want or use it without the .sh extension. If you do this then there is no need to place the script in the bin folder mentioned before

Now you can use the script from command line like this

Calling from other scripts

Slack curl invalid payload

you can call this program from other bash scripts like this for example