Post to Slack in Python

After learning machine learning, I wanted to be notified of the result, so I looked it up and made a note.

Use Incoming Webhook. For more information, go to the Manual (https://api.slack.com/incoming-webhooks).

Register for Incoming Webhooks on Slack

  1. In the Slack app, press "Add an app or custom integration".
  2. The browser will launch and press "Build your own" in the upper right corner.
  3. Press "Make a custom integration".
  4. Press "Incoming Webhook".
  5. Select the channel to post to and create it, and the URL will appear, so copy it.

Write python

Really one liner.

Enter requests with pip.

import requests
import json

requests.post('URL copied above', data = json.dumps({
    'text': u'Test', #Text to post
    'username': u'me', #Post username
    'icon_emoji': u':ghost:', #Emoji to put in the profile image of the post
    'link_names': 1, #Enable mentions
}))

The list of emojis that can be used is here. You can also specify a profile image with ʻicon_url`.

Regarding link_names, I secretly wrote it here.

Recommended Posts

Post to Slack in Python
Post from Python to Slack
Post to vim → Python → Slack
Post to slack with Python 3
Log in to Slack using requests in Python
Post a message from IBM Cloud Functions to Slack in Python
Image characters and post to slack (python slackbot)
To flush stdout in Python
Post to Slack via Subscriber
Login to website in Python
Speech to speech in python [text to speech]
Implement Slack chatbot in Python
POST messages from python to Slack via incoming webhook
Post Jenkins console output to Slack
[Python] How to do PCA in Python
Convert markdown to PDF in Python
How to collect images in Python
Post from python to facebook timeline
How to use SQLite in Python
[Lambda] [Python] Post to Twitter from Lambda!
Try to calculate Trace in Python
Get, post communication memo in Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
6 ways to string objects in Python
How to use PubChem in Python
Easily post to twitter with Python 3
An alternative to `pause` in Python
Quadtree in Python --2
Python in optimization
CURL in python
Updated to Python 2.7.9
[Introduction to Python] How to use class in Python?
Geocoding in python
SendKeys in Python
Install Pyaudio to play wave in python
How to access environment variables in Python
I tried to implement permutation in Python
Method to build Python environment in Xcode 6
Meta-analysis in Python
How to dynamically define variables in Python
How to do R chartr () in Python
Unittest in python
Pin current directory to script directory in Python
[Itertools.permutations] How to put permutations in Python
PUT gzip directly to S3 in Python
Send a message from Python to Slack
Send email to multiple recipients in Python (Python 3)
Convert psd file to png in Python
Sample script to trap signals in Python
I tried to implement PLSA in Python 2
To set default encoding to utf-8 in python
Epoch in Python
Discord in Python
Post Test 3 (Working with PosgreSQL in Python)
How to work with BigQuery in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python