-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


Slack Python

, 04 2017 . 09:44 +
, - Python, Heroku, Travis CI - .

, , . , ?


Heroku + Python Web App



- requirements.txt
- Procfile
- runtime.txt

httplib2
slacker
Flask==0.12
, PyCharm , - .
Httplib2 , Slacker Slack API, Flask , -, .

runtime.txt , .
Procfile
web: python app.py

, app.py
from flask import Flask
from flask import request
from flask import make_response

app = Flask(__name__)

#  
@app.route('/webhook')
def hello_slack():
    #    
    request_json = request.get_json(silent=True, force=True)
    #           dict  ,   
    #   request_json -> response_body_json
    ...
    response_body = json.dumps(response_body_json)
    #     
    response = make_response(response_body)
    response.headers['Content-Type'] = 'application/json'
    #  
    return response

if __name__ == '__main__':
    port = int(os.getenv('PORT', 5000))
    app.run(debug=False, port=port, host='0.0.0.0')

, . , requirements.txt Procfile.

Slack


,
https://YOUR_APP_NAME.herokuapp.com/webhook
, *---*. events API ( , ). challenge-request . - Event Subscriptions . . , , . , /auth, , . , POST- slack.com/api/oauth.access , , , .


Travis CI


. , . curl, , . , , .travis.yml
language: python
python:
  - "3.6"
script:
  python3 -m unittest discover
script , , . ( ) - .

( ) , , . , , , , , . !

, . , , .

!
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/334678/

:  

: [1] []
 

:
: 

: ( )

:

  URL