-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Slack Socket mode and Handler support #1461
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Asher-hss , left some comments below
camel/bots/slack/slack_app.py
Outdated
@@ -55,24 +54,29 @@ class SlackApp: | |||
"/slack/oauth_redirect". | |||
installation_store (Optional[AsyncInstallationStore]): The installation | |||
store for handling OAuth installations. | |||
socket_mode (bool): A flag to enable socket mode for the Slack app, | |||
""" | |||
|
|||
@dependencies_required('slack_bolt') | |||
def __init__( | |||
self, | |||
token: Optional[str] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename token
to a more specific naming align with Slack's official naming
camel/bots/slack/slack_app.py
Outdated
socket_mode (bool): A flag to enable socket mode for the Slack app. | ||
(default is False). If want to use socket mode, set it to True. | ||
And Open the socket mode in the Slack API Applications. | ||
url: https://api.slack.com/apps/ | ||
oauth_mode (bool): A flag to enable OAuth mode for the Slack app. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the format for default value could be improved for all the docstring in this file, refer to https://github.com/camel-ai/camel/blob/master/CONTRIBUTING.md#3-document-parameters-in-the-args-section
else: | ||
response = result | ||
thread_ts = None | ||
await say(text=response, token=token, thread_ts=thread_ts) | ||
|
||
async def on_message( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we ignore messages from the bot itself to avoid infinite loop in async def on_message
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bot message is also a type of normal message. I believe we should not assume that users need to filter out this message. this function have provided sufficient parameters to allow users to decide how to filter it themselves.
if self.mention_me(context, SlackEventBody(**body)): | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you help me understand why we stop it if the bot is mentioned in the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention messages are also a type of normal message. Therefore, mention messages will be listened to by the message listener. As a result, mention messages will be passed to both the message handler and the mention message handler. Since I have set up a separate mention message handling function, I filter out mention messages received by the message listener.
The response generated by the Slack Bolt handler. | ||
""" | ||
return await self._handler.handle(request) | ||
|
||
async def app_mention( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like mention messages are handled both in on_message() and app_mention(), would it trigger duplicate responses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, That’s why I added filter `self.mention_me()' in on_message().
Description
close #1348
solve socket mode and add handler function
Motivation and Context
close #1348
solve socket mode and add handler function
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Implemented Tasks
Checklist
Go over all the following points, and put an
x
in all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!