How to use the slackeventsapi.SlackEventAdapter function in slackeventsapi

To help you get started, we’ve selected a few slackeventsapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github slackapi / python-slack-events-api / tests / test_server.py View on Github external
def test_existing_flask():
    valid_flask = Flask(__name__)
    valid_adapter = SlackEventAdapter("vFO9LARnLI7GflLR8tGqHgdy", "/slack/events", valid_flask)
    assert isinstance(valid_adapter, SlackEventAdapter)
github slackapi / python-slack-events-api / tests / test_events.py View on Github external
import pytest
from slackeventsapi import SlackEventAdapter

ADAPTER = SlackEventAdapter('vFO9LARnLI7GflLR8tGqHgdy')


def test_event_emission(client):
    # Events should trigger an event
    data = pytest.reaction_event_fixture

    @ADAPTER.on('reaction_added')
    def event_handler(event):
        assert event["reaction"] == 'grinning'

    res = client.post(
        '/slack/events',
        data=data,
        content_type='application/json'
    )
github slackapi / python-slack-events-api / tests / test_server.py View on Github external
def test_server_not_flask():
    with pytest.raises(TypeError) as e:
        invalid_flask = "I am not a Flask"
        SlackEventAdapter("vFO9LARnLI7GflLR8tGqHgdy", "/slack/events", invalid_flask)
    assert e.value.args[0] == 'Server must be an instance of Flask'
github slackapi / python-slack-events-api / tests / test_server.py View on Github external
def test_version_header(client):
    # Verify [package metadata header is set
    package_info = SlackEventAdapter("token").server.package_info

    data = pytest.reaction_event_fixture
    res = client.post(
        '/slack/events',
        data=data,
        content_type='application/json')

    assert res.status_code == 200
    assert res.headers["X-Slack-Powered-By"] == package_info
github slackapi / python-slack-events-api / tests / test_server.py View on Github external
def test_existing_flask():
    valid_flask = Flask(__name__)
    valid_adapter = SlackEventAdapter("vFO9LARnLI7GflLR8tGqHgdy", "/slack/events", valid_flask)
    assert isinstance(valid_adapter, SlackEventAdapter)
github seratch / slack-app-examples / reacjilator-python3 / app.py View on Github external
# Slack
import slack
from slackeventsapi import SlackEventAdapter

# --------------------
# Slack API
# Slack Web API Client with sufficient permissions
slack_web_api_client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])

# In order for our application to verify the authenticity
# of requests from Slack, we'll compare the request signature
slack_signing_secret = os.environ["SLACK_SIGNING_SECRET"]

# Create an instance of SlackEventAdapter, passing in our Flask server so it can bind the
# Slack specific routes. The `endpoint` param specifies where to listen for Slack event traffic.
slack_events_adapter = SlackEventAdapter(
    slack_signing_secret,
    endpoint="/slack/events"
)

# --------------------
# Google Translate API

# https://console.cloud.google.com/apis/credentials?project={project id}
# export GOOGLE_APPLICATION_CREDENTIALS=/path/to/{service-account-key}.json
translate_client = translate.Client()

# --------------------
# Load language mapping data
langcode: dict = {}
with open('./langcode.json') as langcode_file:
    langcode = json.load(langcode_file)
github slackapi / python-slack-events-api / example / example.py View on Github external
from slackeventsapi import SlackEventAdapter
from slackclient import SlackClient
import os

# Our app's Slack Event Adapter for receiving actions via the Events API
SLACK_VERIFICATION_TOKEN = os.environ["SLACK_VERIFICATION_TOKEN"]
slack_events_adapter = SlackEventAdapter(SLACK_VERIFICATION_TOKEN, "/slack/events")

# Create a SlackClient for your bot to use for Web API requests
SLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]
CLIENT = SlackClient(SLACK_BOT_TOKEN)

# Example responder to greetings
@slack_events_adapter.on("message")
def handle_message(event_data):
    message = event_data["event"]
    # If the incoming message contains "hi", then respond with a "Hello" message
    if message.get("subtype") is None and "hi" in message.get('text'):
        channel = message["channel"]
        message = "Hello <@%s>! :tada:" % message["user"]
        CLIENT.api_call("chat.postMessage", channel=channel, text=message)
github UQComputingSociety / uqcsbot / uqcsbot / base.py View on Github external
from slackeventsapi import SlackEventAdapter
from slackclient import SlackClient
from . import api, command_handler
import os

SLACK_VERIFICATION_TOKEN = os.environ.get("SLACK_VERIFICATION_TOKEN", "")
SLACK_BOT_TOKEN = os.environ.get("SLACK_BOT_TOKEN", "")

slack_events_adapter = SlackEventAdapter(SLACK_VERIFICATION_TOKEN, "/uqcsbot/events")
slack_client = SlackClient(SLACK_BOT_TOKEN)

command_handler = command_handler.CommandHandler(slack_events_adapter, slack_client)
bot = api.Bot(slack_client)

slackeventsapi

Python Slack Events API adapter for Flask

MIT
Latest version published 3 months ago

Package Health Score

68 / 100
Full package analysis

Similar packages