Skip to content

Commit e9e3e1b

Browse files
committed
refactor(slack): ask user for necessary ids
1 parent 6f37810 commit e9e3e1b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

npiai/tools/slack/__test__/send_and_wait.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import asyncio
22

33
from npiai import agent_wrapper
4-
from npiai.tools.slack import Slack
4+
from npiai.tools import Slack
5+
from npiai.hitl_handler import ConsoleHandler
56

67

78
async def main():
89
async with agent_wrapper(Slack()) as slack:
10+
slack.use_hitl(ConsoleHandler())
11+
912
return await slack.chat(
10-
'Send a direct message to Dolphin (user id: "U071QBWBVCJ") asking if he is doing well, and wait for his reply.'
13+
'Send a direct message to Dolphin asking if he is doing well, and wait for his reply.'
1114
)
1215

1316

npiai/tools/slack/app.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import asyncio
22
import json
33
import os
4+
from typing import Literal
45

56
from slack_sdk.web.async_client import AsyncWebClient, AsyncSlackResponse
67

8+
from npiai.context import Context
79
from npiai.utils import logger
810
from npiai import FunctionTool, function
911
from npiai.error.auth import UnauthorizedError
@@ -68,6 +70,20 @@ def _get_messages_from_response(self, response: AsyncSlackResponse):
6870

6971
return sorted(messages, key=lambda x: float(x['thread_id']))
7072

73+
@function
74+
async def ask_for_id(self, ctx: Context, name: Literal['user', 'channel', 'thread']):
75+
"""
76+
Ask the user to provide recipient's user id, channel id, or thread id.
77+
Args:
78+
ctx: NPi context.
79+
name: The type of id to ask for.
80+
"""
81+
return await self.hitl.input(
82+
ctx,
83+
self.name,
84+
f"Please provide recipient's {name} ID to send messages to",
85+
)
86+
7187
@function
7288
async def list_channels(self):
7389
"""Get a list of all Slack channels"""

0 commit comments

Comments
 (0)