● Slack Help Center 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
Issue the Incoming Webhook URL by following the steps in Setting Up an Incoming Webhook.
If you haven't registered for Google Cloud Platform, do so.
--Go to "Cloud Function". --Create a function with "Create Function". The settings are as follows
Name: Optional Allotted memory: optional Trigger: HTTP Authentication: Allow unauthenticated calls Source code: inline editor Runtime: Python 3.7 Function to be executed: Function name described in the source (slack_notice in sample)
sample.py
import requests
import json
def slack_notice(request):
webhook_url = "https://hooks.slack.com/<Incoming Webhook URL>"
request_json = request.get_json()
if 'commits' in request_json:
name = request_json['commits'][0]['author']['name']
text = name+"Pushed."
requests.post(webhook_url, data = json.dumps({
"text": text
}))
Go to "Setteing"-> "Webhooks"-> "Add webhook" and set as below
Payload URL: URL written in the trigger of Google Cloud Platform Content type:application/json SSL verification:Enable SSL verification Which events would you like to trigger this webhook?:Just the push event. Active: Check
Big
Recommended Posts