Slack Bot - jupark33/Spring GitHub Wiki

  1. Slack ์—์„œ ์ƒˆ๋กœ์šด ์•ฑ ์ƒ์„ฑ
  2. ์•ฑ ๋ฉ”๋‰ด์—์„œ Slash Commands ์„ ํƒ
  3. ๋ช…๋ น์–ด (์˜ˆ : /report) ๋ฅผ ๋“ฑ๋กํ•˜๊ณ  ์š”์ฒญ URL์„ ์„ค์ •ํ•œ๋‹ค. ๋ด‡์ด ์‹คํ–‰๋  ์„œ๋ฒ„์˜ Endpoint ์ด๋‹ค.
  4. ํŒŒ์ด์„ ์œผ๋กœ ๋ด‡ ์ฝ”๋“œ ์ž‘์„ฑ
  5. Slack Workspace์— ์•ฑ ์„ค์น˜
  6. ํŒŒ์ด์„  ๋ด‡ ์ฝ”๋“œ

โ€˜โ€™โ€˜python

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/slack/command', methods=['POST'])
def slack_command():
    data = request.form
    user_command = data.get('text')
    user_name = data.get('user_name')

    # ๋ช…๋ น์–ด ์ฒ˜๋ฆฌ ๋…ผ๋ฆฌ
    response_message = f"Hello {user_name}, you entered: {user_command}"

    return jsonify({
        "response_type": "in_channel", # ์‘๋‹ต์„ ๊ณต๊ฐœ์ ์œผ๋กœ ๋ณด๋ƒ…๋‹ˆ๋‹ค.
        "text": response_message
    })

if __name__ == "__main__":
    app.run(port=3000)