-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (27 loc) · 932 Bytes
/
app.py
File metadata and controls
38 lines (27 loc) · 932 Bytes
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
import time
import random
from flask import Flask, request, jsonify
from services.waha import Waha
from bot.ai_bot import AIBot
app = Flask(__name__)
@app.route('/api/chatbot/webhook/', methods=['POST'])
def webhook():
data = request.json
chat_id = data['payload']['from']
received_message = data['payload']['body']
is_group = '@g.us' in chat_id
is_status = 'status@broadcast' in chat_id
if is_group or is_status:
return jsonify({'status': 'success', 'message': 'Group/status message ignored'}), 200
waha = Waha()
ai_bot = AIBot()
waha.start_typing(chat_id=chat_id)
response = ai_bot.invoke(user_message=received_message)
waha.send_message(
chat_id=chat_id,
message=response,
)
waha.stop_typing(chat_id=chat_id)
return jsonify({'status': 'success'}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)