Skip to content

Instantly share code, notes, and snippets.

@ponsuke0531
Last active January 6, 2019 03:35
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 ponsuke0531/ece3d5e127b4a11c287c558aa9a8cbd5 to your computer and use it in GitHub Desktop.
Save ponsuke0531/ece3d5e127b4a11c287c558aa9a8cbd5 to your computer and use it in GitHub Desktop.
はじめてのPythonでSlackとつながってみる
import json, requests
WEB_HOOK_URL = "https://hooks.slack.com/services/"
WEB_HOOK_URL += "WebhookURLの後半"
requests.post(WEB_HOOK_URL, data=json.dumps({
# channelでメッセージを送るチャネルが指定できます。
'channel': '#チャネル名',
'text': "<@メンション相手のメンバーID> メンションを送るには `<@メンバーID>` を指定する。",
'link_names': 1,
'username': 'usernameを指定すると投稿するユーザを変えられる。',
# icon_emoji指定すると投稿するユーザのアイコンを変更できます。
'icon_emoji': ':monkey_face:',
'attachments': [{
# titleのリンクをクリックするとtitle_linkで設定したページへ飛びます。
'title': 'attachmentsを使ってみる。',
'title_link': 'https://api.slack.com/docs/message-attachments',
'text': '`actions` でボタンも追加できる。',
# mrkdwn_inにtext指定すると文字の装飾が有効になる。
'author_name': '<@メンバーID>',
'mrkdwn_in': ['text'],
'color': '#2eb886',
'actions': [
{
'name': 'like',
'text': '好き',
'type': 'button',
'value': 'like'
},
{
'name': 'hate',
'text': '嫌い',
'type': 'button',
'value': 'hate'
}
],
'footer': ':monkey:',
}]
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment