Files
OpenBB/bots/slack/run_slack.py
Colin Delahunty 6538c0ce14 Expanding bot tests (#1561)
* Expanding bot tests

* expanded tests

* Added tests

* Added stock test

* Fix filepath

* Attempted mock

* Bots : test_run_telegram

* Enhance tests

* Fixed black

* Expanded tests

* Added fix

* Ingore interactive files

* Removed bot dependency installation from tests

* Fix one black

* Fixed black

* Added init.py

* Added pylint disables

* Added skip

Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
2022-04-02 14:47:46 -04:00

44 lines
1.1 KiB
Python

import logging
import os
from dotenv import load_dotenv
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from bots.common.commands_dict import commands
from bots.common.helpers import non_slash
from bots.helpers import ShowView
load_dotenv()
app = App(token=os.environ.get("OPENBB_SLACK_APP_TOKEN", None))
available_commands = list(commands.keys())
@app.event("message")
def processMessage(event, client):
"""Process users' commands"""
channel_id = event.get("channel")
user_id = event.get("user")
text = event.get("text")
non_slash(
text,
lambda x: client.chat_postMessage(
**{"channel": channel_id, "username": user_id, "text": x}
),
lambda x, y, z: ShowView().slack(x, channel_id, user_id, client, y, **z),
)
if __name__ == "__main__":
# TODO: replace with GST logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
handler = SocketModeHandler(
app,
os.environ["OPENBB_SLACK_BOT_TOKEN"],
)
handler.start()