Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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