-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetadata.py
37 lines (29 loc) · 1.22 KB
/
metadata.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
from common_imports import *
from gooddata_sdk import GoodDataSdk
app = slack_bolt.App(token=os.environ["SLACK_BOT_TOKEN"])
CONVERSATION_ID = None # You can create and specify conversation_id to be used.
chatbot = Chatbot({"session_token": os.environ["CHATGPT_TOKEN"]}, conversation_id=CONVERSATION_ID)
sdk = GoodDataSdk.create(os.environ["GOODDATA_HOST"], os.environ["GOODDATA_TOKEN"])
def feed_chatbot():
workspaces = sdk.catalog_workspace.list_workspaces()
chatbot.ask(str(workspaces))
@app.event("app_mention")
def bot_is_mentioned(
event: dict[str, Any],
say: slack_bolt.context.context.Say,
):
"""
In this use case, we can ask the chatbot to give us the names of workspaces.
Thanks to the fact that we feed the chatbot with metadata before.
The chatbot will be able to answer us.
e.g. Give me the names of workspaces
"""
message = event["text"].split(" ", 1)[1]
try:
response = chatbot.ask(message, conversation_id=CONVERSATION_ID)
say(response["message"])
except Exception: # noqa
say("Sorry, I could not process your prompt. Please try it again.")
if __name__ == "__main__":
feed_chatbot()
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()