Exemplo n.º 1
0
def authorize(enterprise_id, team_id, user_id, client: WebClient, logger):
    logger.info(f"{enterprise_id},{team_id},{user_id}")
    # You can implement your own logic here
    token = os.environ["MY_TOKEN"]
    return AuthorizeResult.from_auth_test_response(
        auth_test_response=client.auth_test(token=token),
        bot_token=token,
    )
Exemplo n.º 2
0
def user_authorize(enterprise_id, team_id, user_id, client: WebClient):
    assert enterprise_id == "E111"
    assert team_id == "T111"
    assert user_id == "W99999"
    auth_test = client.auth_test(token=valid_user_token)
    return AuthorizeResult.from_auth_test_response(
        auth_test_response=auth_test,
        user_token=valid_user_token,
    )
Exemplo n.º 3
0
    def deviceStartComm(self, device):
        self.logger.debug(f"{device.name}: Starting Device")

        client = WebClient(token=device.pluginProps['bot_token'])
        auth_info = client.auth_test()
        self.slack_accounts[auth_info['team_id']] = device.id
        self.logger.info(f"{device.name}: Connected to Slack Workspace '{auth_info['team']}'")

        self.channels[device.id] = [
            (channel["id"], channel["name"])
            for channel in client.conversations_list()['channels']
        ]
        self.logger.info("{}: Channel List Updated".format(device.name))
        self.logger.debug("{}: Channels: {}".format(device.name, self.channels[device.id]))
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        description='Simple Bugzilla triage helper bot for Slack.')
    parser.add_argument('-c',
                        '--config',
                        metavar='FILE',
                        default='~/.triagebot',
                        help='config file')
    parser.add_argument('-d',
                        '--database',
                        metavar='FILE',
                        default='~/.triagebot-db',
                        help='database file')
    args = parser.parse_args()

    # Read config
    with open(os.path.expanduser(args.config)) as fh:
        config = DottedDict(yaml.safe_load(fh))
        config.database = os.path.expanduser(args.database)
    env_map = (('TRIAGEBOT_SLACK_APP_TOKEN',
                'slack-app-token'), ('TRIAGEBOT_SLACK_TOKEN', 'slack-token'),
               ('TRIAGEBOT_BUGZILLA_KEY', 'bugzilla-key'))
    for env, config_key in env_map:
        v = os.environ.get(env)
        if v:
            setattr(config, config_key, v)

    # Connect to services
    client = WebClient(token=config.slack_token)
    # store our user ID
    config.bot_id = client.auth_test()['user_id']
    bzapi = bugzilla.Bugzilla(config.bugzilla,
                              api_key=config.bugzilla_key,
                              force_rest=True)
    if not bzapi.logged_in:
        raise Exception('Did not authenticate')
    db = Database(config)

    # Start socket-mode listener in the background
    socket_client = SocketModeClient(
        app_token=config.slack_app_token,
        web_client=WebClient(token=config.slack_token))
    socket_client.socket_mode_request_listeners.append(
        lambda socket_client, req: process_event(config, socket_client, req))
    socket_client.connect()

    # Run scheduler
    Scheduler(config, client, bzapi, db).run()
Exemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser(
        description='Slack bot to send periodic 1:1 invitations.')
    parser.add_argument('-c',
                        '--config',
                        metavar='FILE',
                        default='~/.11bot',
                        help='config file')
    parser.add_argument('-d',
                        '--database',
                        metavar='FILE',
                        default='~/.11bot-db',
                        help='database file')
    args = parser.parse_args()

    # Self-test
    Grouping.selftest()

    # Read config
    with open(os.path.expanduser(args.config)) as fh:
        config = DottedDict(yaml.safe_load(fh))
        config.database = os.path.expanduser(args.database)
    env_map = (
        ('ELEVENBOT_APP_TOKEN', 'app-token'),
        ('ELEVENBOT_TOKEN', 'token'),
    )
    for env, config_key in env_map:
        v = os.environ.get(env)
        if v:
            setattr(config, config_key, v)

    # Connect to services
    client = WebClient(token=config.token)
    # store our user ID
    config.bot_id = client.auth_test()['user_id']
    db = Database(config)

    # Start socket-mode listener in the background
    socket_client = SocketModeClient(app_token=config.app_token,
                                     web_client=WebClient(token=config.token))
    socket_client.socket_mode_request_listeners.append(
        lambda socket_client, req: process_event(config, socket_client, req))
    socket_client.connect()

    # Run scheduler
    Scheduler(config, client, db).run()
#!/usr/bin/env python
# queries the slack api with the email address and gets back a user id

import os
import sys
from relay_sdk import Interface, Dynamic as D
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

relay = Interface()

api_token = relay.get(D.connection.apiToken)
email_address = relay.get(D.email)

try:
    client = WebClient(api_token)
    client.auth_test()
except SlackApiError as e:
    sys.stderr.write('Unable to authenticate with Slack')
    exit(1)

try:
    response = client.users_lookupByEmail(email=email_address)

    if response and response['user']:
        relay.outputs.set("memberID", response['user']['id'])
except SlackApiError as e:
    sys.stderr.write('The error return from the Slack API is: ' +
                     e.response["error"])
    exit(1)
Exemplo n.º 7
0
logging.basicConfig(level=logging.ERROR)
#logging.basicConfig(level=logging.INFO)
#logging.basicConfig(level=logging.DEBUG)

config = toml.load(open('secret.toml'))

slack_app_token = config['socket-mode']['token']

# user = hadacchi, this token grant as hadacchi to bot
slack_user_token = config['socket-mode']['user_oauth_access_token']
# bot user = garie, this token only grant as garie to bot
slack_bot_token = config['socket-mode']['bot_user_oauth_access_token']

# this is keyword when this bot mentioned
client = WebClient(token=slack_bot_token)
bot_user_id = client.auth_test()['user_id']
del client

app = App(token=slack_bot_token)

### event API ###


# slack message control
@app.message(re.compile(f'<@{bot_user_id}> *clear *([^ ]*)$'))
def clear_command(message, say, logger, context):
    '''remove message in the channel

    `@BOTNAME clear [all|NUM]`

    where `NUM` is the number that you want to remove.