Check the Slack documentation to get the URL.
· [Using Incoming Webhooks in Slack] (https://slack.com/intl/ja-jp/help/articles/115005265063-Slack-%E3%81%A7%E3%81%AE-Incoming-Webhook-%E3%81%AE%E5%88%A9%E7%94%A8) · [Sending messages using Incoming Webhooks] (https://api.slack.com/messaging/webhooks)
=> ”https://hooks.slack.com/services/xxxxxxxxx/xxxxxxx/0KX1TxxxxxwP1xxxxx61axxxxx” Get a URL like
Log in to the IBM Cloud console-> Go to Functions https://cloud.ibm.com/login
・ [Create Action] (https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-actions#actions_create_ui) Create an action from the console.
** It is assumed that the IBM Cloud Function service has already been created.
-> create -> Select Action
-> Specify the action name and package, and select Python as the runtime.
Enter the Code. Sample code
import requests
import json
def main(dict):
body={'username':'Alert','icon_emoji':':star:','text':'IBM Cloud Functions Test'}
url = "https://hooks.slack.com/services/xxxxxxxxx/xxxxxxx/0KX1TxxxxxwP1xxxxx61axxxxx" #<-URL obtained from Slack
response = requests.post(url,data=json.dumps(body))
return {"message" : "IBM Cloud Functions test post to slack"}
Enter usename, icom_emoji, and text (message) in the body part.
For other options, refer to the manual. ・ Chat.postMessage (https://api.slack.com/methods/chat.postMessage)
-> Press Save at the top right of the code.
-> The Save button changes to Invoke. Perform Invoke. (URL is replaced with the target content)
-> The execution result is output in the right column of the code.
As a result, the Slack channel will be notified as follows:
that's all.
reference: -IBM Cloud Functions
Recommended Posts