Add slack tunnel
This commit is contained in:
+2
-1
@@ -9,6 +9,7 @@ history.txt
|
|||||||
aios_shell_history.txt
|
aios_shell_history.txt
|
||||||
math_school_env.db
|
math_school_env.db
|
||||||
workflows.db
|
workflows.db
|
||||||
|
venv-linux
|
||||||
|
venv_test
|
||||||
|
|
||||||
rootfs/test_doc/
|
rootfs/test_doc/
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
from slack_bolt.adapter.socket_mode.websockets import AsyncSocketModeHandler
|
||||||
|
from slack_bolt.app.async_app import AsyncApp
|
||||||
|
|
||||||
|
from aios.frame.tunnel import AgentTunnel
|
||||||
|
from aios.proto.agent_msg import AgentMsg
|
||||||
|
|
||||||
|
|
||||||
|
class SlackTunnel(AgentTunnel):
|
||||||
|
type: str
|
||||||
|
token: str
|
||||||
|
app_token: str
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.type = "SlackTunnel"
|
||||||
|
self.token = ""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def register_to_loader(cls):
|
||||||
|
async def load_slack_tunnel(config: dict) -> AgentTunnel:
|
||||||
|
result_tunnel = SlackTunnel()
|
||||||
|
if await result_tunnel.load_from_config(config):
|
||||||
|
return result_tunnel
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
AgentTunnel.register_loader("SlackTunnel", load_slack_tunnel)
|
||||||
|
|
||||||
|
async def load_from_config(self, config: dict) -> bool:
|
||||||
|
self.target_id = config["target"]
|
||||||
|
self.tunnel_id = config["tunnel_id"]
|
||||||
|
|
||||||
|
self.type = "SlackTunnel"
|
||||||
|
self.token = config["token"]
|
||||||
|
self.app_token = config["app_token"]
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def post_message(self, msg: AgentMsg) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def start(self) -> bool:
|
||||||
|
app = AsyncApp(token=self.token)
|
||||||
|
|
||||||
|
@app.event("message")
|
||||||
|
async def _handle_message(event, say):
|
||||||
|
await self._process_message(event)
|
||||||
|
|
||||||
|
asyncio.create_task(AsyncSocketModeHandler(app, self.app_token).start_async())
|
||||||
|
return True
|
||||||
|
|
||||||
|
async def close(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def _process_message(self, msg: AgentMsg) -> None:
|
||||||
|
return
|
||||||
@@ -154,3 +154,4 @@ html2text
|
|||||||
docx2txt
|
docx2txt
|
||||||
opencv-python
|
opencv-python
|
||||||
discord.py
|
discord.py
|
||||||
|
slack_bolt
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
|||||||
from prompt_toolkit.completion import WordCompleter
|
from prompt_toolkit.completion import WordCompleter
|
||||||
from prompt_toolkit.styles import Style
|
from prompt_toolkit.styles import Style
|
||||||
|
|
||||||
|
from slack_tunnel import SlackTunnel
|
||||||
directory = os.path.dirname(__file__)
|
directory = os.path.dirname(__file__)
|
||||||
sys.path.append(directory + '/../../')
|
sys.path.append(directory + '/../../')
|
||||||
|
|
||||||
@@ -236,6 +237,7 @@ class AIOS_Shell:
|
|||||||
TelegramTunnel.register_to_loader()
|
TelegramTunnel.register_to_loader()
|
||||||
EmailTunnel.register_to_loader()
|
EmailTunnel.register_to_loader()
|
||||||
DiscordTunnel.register_to_loader()
|
DiscordTunnel.register_to_loader()
|
||||||
|
SlackTunnel.register_to_loader()
|
||||||
user_data_dir = str(AIStorage.get_instance().get_myai_dir())
|
user_data_dir = str(AIStorage.get_instance().get_myai_dir())
|
||||||
tunnels_config_path = os.path.abspath(f"{user_data_dir}/etc/tunnels.cfg.toml")
|
tunnels_config_path = os.path.abspath(f"{user_data_dir}/etc/tunnels.cfg.toml")
|
||||||
tunnel_config = None
|
tunnel_config = None
|
||||||
@@ -294,6 +296,10 @@ class AIOS_Shell:
|
|||||||
case "discord":
|
case "discord":
|
||||||
tunnel_config["type"] = "DiscordTunnel"
|
tunnel_config["type"] = "DiscordTunnel"
|
||||||
input_table["token"] = UserConfigItem("discord bot token\n You can get it from https://discord.com/developers/applications ,read https://discordpy.readthedocs.io/en/stable/discord.html for more details")
|
input_table["token"] = UserConfigItem("discord bot token\n You can get it from https://discord.com/developers/applications ,read https://discordpy.readthedocs.io/en/stable/discord.html for more details")
|
||||||
|
case "slack":
|
||||||
|
tunnel_config["type"] = "SlackTunnel"
|
||||||
|
input_table["token"] = UserConfigItem("slack bot token\n You can get it from https://api.slack.com/apps")
|
||||||
|
input_table["app_token"] = UserConfigItem("slack app token\n You can get it from https://api.slack.com/apps")
|
||||||
case _:
|
case _:
|
||||||
error_text = FormattedText([("class:error", f"tunnel type {tunnel_type}not support!")])
|
error_text = FormattedText([("class:error", f"tunnel type {tunnel_type}not support!")])
|
||||||
print_formatted_text(error_text,style=shell_style)
|
print_formatted_text(error_text,style=shell_style)
|
||||||
|
|||||||
Reference in New Issue
Block a user