Skip to content
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

Add slack message adapter #22

Merged
merged 1 commit into from
Feb 23, 2024
Merged

Add slack message adapter #22

merged 1 commit into from
Feb 23, 2024

Conversation

timkpaine
Copy link
Member

@timkpaine timkpaine commented Feb 6, 2024

Still needs a lot of work, just putting this draft PR up so its out there

  • finish basic functionality
    • receive messages and map to SlackMessage struct
    • send messages, map from SlackMessage struct
    • handle tagged users
    • Map user and channel IDs to user and channel names
    • Pull user email from user id and make available on message
    • disambiguate public, private, and direct messages
    • Handle emoji reactions
  • add unit tests with mocked out slack SDK
  • add extras to pyproject.toml
  • have subscribe return ts[[msg]] to match SymphonyAdapter

fixes: #17
ref: #35

MVP:

import csp
from csp import ts
from csp.adapters.slack import SlackAdapterManager, SlackMessage

SLACK_APP_TOKEN = "xapp-..."
SLACK_BOT_TOKEN = "xoxb-..."

@csp.node
def node(msg: ts[SlackMessage]) -> ts[SlackMessage]:
    if csp.ticked(msg):
        text = f"Hello <@{msg.user_id}>!"
        return SlackMessage(
            channel=msg.channel,
            channel_id=msg.channel_id,
            msg=text,
        )

def graph():
    am = SlackAdapterManager(SLACK_APP_TOKEN, SLACK_BOT_TOKEN)
    am.publish(node(am.subscribe()))

csp.run(graph, realtime=True)
Screenshot 2024-02-06 at 14 06 37

@timkpaine timkpaine added tag: wip PRs that are a work in progress - converted to drafts adapter: new Issues and PRs related to creating new input/output adapters labels Feb 6, 2024
@timkpaine timkpaine force-pushed the tkp/slack branch 5 times, most recently from 660bcf7 to 3be4e74 Compare February 8, 2024 21:12
@timkpaine timkpaine changed the title [WIP] adding slack message adapter Add slack message adapter Feb 8, 2024
@timkpaine timkpaine marked this pull request as ready for review February 8, 2024 21:18
@timkpaine timkpaine mentioned this pull request Feb 8, 2024
@timkpaine timkpaine added type: feature Issues and PRs related to new features and removed tag: wip PRs that are a work in progress - converted to drafts labels Feb 8, 2024
@timkpaine timkpaine force-pushed the tkp/slack branch 3 times, most recently from 78ad1da to 20cbd69 Compare February 13, 2024 18:58
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
@timkpaine timkpaine merged commit b76eee5 into main Feb 23, 2024
14 checks passed
@timkpaine timkpaine deleted the tkp/slack branch February 23, 2024 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapter: new Issues and PRs related to creating new input/output adapters type: feature Issues and PRs related to new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a data adapter for slack messages
2 participants