-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-slack.py
More file actions
67 lines (51 loc) · 1.67 KB
/
Copy pathapp-slack.py
File metadata and controls
67 lines (51 loc) · 1.67 KB
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
import os
from flask import Flask, request
from slack_bolt import App
from slack_bolt.adapter.flask import SlackRequestHandler
from browser_use import Agent
from browseruse_runner import run_browseruse
import threading
# ----------------------------
# Slack App initialization
# ----------------------------
slack_app = App(
token=os.environ["SLACK_BOT_TOKEN"],
signing_secret=os.environ["SLACK_SIGNING_SECRET"],
)
flask_app = Flask(__name__)
handler = SlackRequestHandler(slack_app)
def run_and_post(channel_id, topic, client):
try:
result = run_browseruse(topic)
MAX_LEN = 3000
chunks = [result[i:i+MAX_LEN] for i in range(0, len(result), MAX_LEN)]
for chunk in chunks:
client.chat_postMessage(
channel=channel_id,
text=chunk # 🔥 NO blocks
)
except Exception as e:
client.chat_postMessage(
channel=channel_id,
text=f"❌ Error while fetching events:\n{str(e)}"
)
@slack_app.command("/events")
def event_command(ack, respond, command, client):
ack()
topic = command["text"]
channel_id = command["channel_id"]
if not topic.strip():
respond("❌ Please provide a topic. Example:\n`/event tech events in Dublin`")
return
respond("⏳ Searching for events across platforms…")
# Run BrowserUse in background thread
threading.Thread(
target=run_and_post,
args=(channel_id, topic, client),
daemon=True
).start()
@flask_app.route("/slack/events", methods=["POST"])
def slack_events():
return handler.handle(request)
if __name__ == "__main__":
flask_app.run(port=3000)