-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
70 lines (62 loc) · 1.97 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is a simple echo bot using Web Server Gateway Interface (WSGI) and Flask
The bot can be running completely as a serverless function
It receives payload data from the incoming webhooks and forward it to the target group chat
"""
import logging
import telebot
import os
import json
import flask
from dotenv import load_dotenv
load_dotenv()
API_TOKEN = os.getenv("API_TOKEN")
CHAT_ID = os.getenv("CHAT_ID")
WEBHOOK_PATH = os.getenv("WEBHOOK_PATH")
logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
bot = telebot.TeleBot(API_TOKEN)
app = flask.Flask(__name__)
@app.route(WEBHOOK_PATH, methods=["POST"])
def webhook():
if flask.request.headers.get("content-type") == "application/json":
raw_data = flask.request.get_json()
logger.info(raw_data)
if "id" in raw_data.keys():
payload = {
"id": raw_data["id"],
"name": raw_data["name"],
"url": raw_data["url"],
"created_by": raw_data["created_by"],
"started": raw_data["started"],
"finished": raw_data["finished"],
"status": raw_data["status"],
"inventory": raw_data["inventory"],
"project": raw_data["project"],
"playbook": raw_data["playbook"],
"credential": raw_data["credential"],
"limit": raw_data["limit"],
}
bot.send_message(
CHAT_ID,
json.dumps(
payload,
ensure_ascii=False,
indent=4,
sort_keys=True
)
)
bot.send_message(
CHAT_ID,
json.dumps(
raw_data,
ensure_ascii=False,
indent=4,
sort_keys=True
)
)
return flask.jsonify({"result": "ok!"})
else:
flask.abort(403)