Skip to content

Instantly share code, notes, and snippets.

@gsherman
Created September 19, 2014 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsherman/b25256790ac42e70d2de to your computer and use it in GitHub Desktop.
Save gsherman/b25256790ac42e70d2de to your computer and use it in GitHub Desktop.
post a message to a slack channel
@echo off
set Count=0
for %%a in (%*) do set /a Count+=1
if %count% NEQ 2 goto usage
SET message=%1
SET channel=%2
SET token=mySecretToken
SET url=https://ourSlackAccount.slack.com/services/hooks/incoming-webhook?token=%token%
SET data=payload={"channel": "%channel%","text":%message%,"username": "focus-bot"}
REM escape all the double quotes
SET data=%data:"=\"%
REM wrap in double quotes
SET data="%data%"
c:
cd %~dp0
..\curl\curl -k -X POST --data-urlencode %data% %url%
goto done
:usage
echo.
echo Invalid usage
echo Usage: slack-message.bat message channel(include the leading #)
echo.
:done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment