token = os.environ["MY_TOKEN"]
    return AuthorizeResult.from_auth_test_response(
        auth_test_response=await client.auth_test(token=token),
        bot_token=token,
    )


app = AsyncApp(signing_secret=os.environ["SLACK_SIGNING_SECRET"], authorize=authorize)


@app.event("app_mention")
async def event_test(body, say, logger):
    logger.info(body)
    await say("What's up?")


@app.command("/hello-bolt-python")
# or app.command(re.compile(r"/hello-.+"))(test_command)
async def command(ack, body):
    user_id = body["user_id"]
    await ack(f"Hi <@{user_id}>!")


if __name__ == "__main__":
    app.start(3000)

# pip install slack_bolt
# export SLACK_SIGNING_SECRET=***
# export MY_TOKEN=xoxb-***
# python app.py
Example #2
0
        tasks = pseudo_database.get(user_id, [])
        tasks.append(new_task)
        pseudo_database[user_id] = tasks

        blocks = []
        for task in tasks:
            blocks.append(
                {
                    "type": "section",
                    "text": {"type": "plain_text", "text": task["task_name"]},
                }
            )
            blocks.append({"type": "divider"})

        await client.views_publish(
            user_id=user_id,
            view={
                "type": "home",
                "title": {"type": "plain_text", "text": "Your tasks!"},
                "blocks": blocks,
            },
        )
    except Exception as err:
        await fail(error={"message": f"Something wrong! {err}"})


app.step(copy_review_step)

if __name__ == "__main__":
    app.start(3000)  # POST http://localhost:3000/slack/events
Example #3
0
    )
    message_archive_url = await carmille.fetch.get_message_archive(
        context.client, channel_id, channel_name, start_time, end_time,
        user_tz_offset)
    await respond(
        text=
        f"This archive is done, and you can pick it up at `{message_archive_url}`. Have a nice day!"
    )


@app.error
async def global_error_handler(error, body, logger):
    logger.exception(error)
    logger.info(body)


if __name__ == "__main__":
    # Check that the S3 variables are set.
    # On app startup, the library will check for SLACK_CLIENT_ID and SLACK_CLIENT_SECRET itself.
    S3_API_ENDPOINT = os.environ.get('S3_API_ENDPOINT')
    S3_BUCKET = os.environ.get('S3_BUCKET')
    S3_ACCESS_KEY = os.environ.get('S3_ACCESS_KEY')
    S3_SECRET_KEY = os.environ.get('S3_SECRET_KEY')
    S3_WEBSITE_PREFIX = os.environ.get('S3_WEBSITE_PREFIX')
    if not (S3_API_ENDPOINT and S3_BUCKET and S3_ACCESS_KEY and S3_SECRET_KEY
            and S3_WEBSITE_PREFIX):
        sys.exit(
            "You must set S3_API_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY, S3_SECRET_KEY, S3_WEBSITE_PREFIX, SLACK_CLIENT_ID, SLACK_CLIENT_SECRET, and SLACK_SIGNING_SECRET in the environment to start this."
        )
    app.start(8000)
Example #4
0
                isDownloaded = True
                process_resume(textract_client=textract_client,
                               comprehend_client=comprehend_client,
                               file_name=file_name,
                               s3_client=s3_client,
                               es_client=es_client)

            else:
                await asyncio.sleep(1)
                counter += 1
        if os.path.exists(file_path):
            os.remove(path=file_path)
    else:
        await say(
            text="Sorry! No file was found with the name {}".format(file_name),
            channel=channel_id)


@app.event("file_shared")
async def file_was_shared():
    pass


@app.event({"type": "message", "subtype": "message_deleted"})
async def file_delete():
    pass


if __name__ == '__main__':
    app.start(port=int(os.environ.get("PORT", 3000)))
Example #5
0
from slack_bolt.async_app import AsyncApp
from slack_sdk.web.async_client import AsyncWebClient

logging.basicConfig(level=os.getenv("LOG_LEVEL") or logging.INFO)
save_events = False

slack = AsyncApp(
    token=os.environ.get("SLACK_BOT_TOKEN"),
    signing_secret=os.environ.get("SLACK_SIGNING_SECRET"),
)


@slack.event({
    "type": "message",
    "channel": BOT_SERVICE_CHANNEL,
    "subtype": "file_share",
    "user": "******",
})
async def process_azure_email(client: AsyncWebClient, event: dict[str, Any]):
    if save_events:
        with open(f"data/json/{event['event_ts']}.json", "w") as f:
            json.dump(event, f, indent=4, ensure_ascii=False)
        return

    headers, plain_text, file_url = preprocess_slack_event(event)
    asyncio.create_task(work(client, headers, plain_text, file_url))


if __name__ == "__main__":
    slack.start(SERVER_PORT)