Whisk Deploy — Slack Package
OpenWhisk offers a Slack Package which can be used to post messages to Slack. Lets look at how we can create package binidng using wskdeploy:
Step 1: Create a manifest file (manifest.yaml)
To create slack package binding, we have to specify it as one of the dependencies using location as /whisk.system/slack in manifest.yaml file:
First, we need to setup an incoming webhook integration in our slack workspace. Configure new webhook for the slack channel we need to send messages to by following step by step instructions from here.
Now, we can integrate this slack package into our application to send a message to slack channel every hour using the following manifest.yaml:
You can get an action file post-to-slack.js
from here.
Step 2: Create a deployment file (deployment.yaml)
Step 3: Deploy a sample application
./wskdeploy -p ~/AppToPostToSlack/
____ ___ _ _ _ _ _
/\ \ / _ \ _ __ ___ _ __ | | | | |__ (_)___| | __
/\ /__\ \ | | | | '_ \ / _ \ '_ \| | | | '_ \| / __| |/ /
/ \____ \ / | |_| | |_) | __/ | | | |/\| | | | | \__ \ <
\ \ / \/ \___/| .__/ \___|_| |_|__/\__|_| |_|_|___/_|\_\
\ __\/ |_|Packages:
Name: SlackPackage
bindings:
* dependency: slack-package-to-post-messages
location: /whisk.system/slack * action: post-to-slack
bindings:
- message : "Hello from WskDeploy!"
- slack_package : "slack-package-to-post-messages"
annotations:Triggers:
* trigger: everyhour
bindings:
- cron : "0 */1 * * *"
annotations:
- name: feed value: /whisk.system/alarms/alarmRules
* rule: post-to-slack-every-hour
- trigger: everyhour
- action: SlackPackage/post-to-slackDo you really want to deploy this? (y/N): y
Deployment completed successfully.
At this point, we have an action post-to-slack configured to run every hour. We can verify our deployment by firing a trigger and checking if action is invoked by following instructions from Whisk Deploy — Action, Trigger, and Rule. Once we have the everyhour trigger fired, we should recieve a new message on our slack channel:
Activation: post-to-slack (9909dd5229e84526bff9902a2cd860df)
[
"2017-09-12T23:05:17.17872899Z stdout: Hello from WskDeploy!",
"2017-09-12T23:05:17.549177677Z stdout: Posted message to slack"
]
Enjoy!