Beispiel #1
0
import os
from flask import Flask
from slackify import Slackify, request, reply_text, Slack, ACK

# Initialize App
app = Flask(__name__)
slackify = Slackify(app=app)
cli = Slack(os.getenv('SLACK_BOT_TOKEN'))


@slackify.command
def update_home_view():
    user = request.form['user_id']
    sample = {
        "type": "home",
        "blocks": [
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": "A simple stack of blocks for the simple sample Block Kit Home tab."
                }
            },
            {
                "type": "actions",
                "elements": [
                    {
                        "type": "button",
                        "action_id": "tell_joke",
                        "text": {
                            "type": "plain_text",
Beispiel #2
0
import os
from flask import Flask
from slackify import Slackify, Slack

# Important! Before running set FLASK_APP=examples.async_task:app
app = Flask(__name__)
slackify = Slackify(app=app)

slack = Slack(os.environ["SLACK_BOT_TOKEN"])


@slackify.event("message")
def handle_message(payload):
    """Listen to messages containing `python` and react with python emoji

    Note:
        Your event handler function *MUST* accept a positional argument with the event payload

    Preconditions:
        - Setup event subscription https://api.slack.com/events-api and point to `/slack/events` uri
        - Suscribe to `message.channels` events so your app gets notified of this event
    """
    event = payload["event"]
    if event.get("subtype") is None and 'python' in event.get('text', ''):
        slack.reactions_add(name='snake',
                            channel=event["channel"],
                            timestamp=event['ts'])
Beispiel #3
0
import time
from slackify import Flack, async_task, reply_text, Slack

app = Flack(__name__)
cli = Slack('xoxb-SECRET-token')


@app.command()
def hello():
    my_background_job()
    return reply_text('Instant Response')


@async_task
def my_background_job():
    """Non blocking long task"""
    time.sleep(5)  # Wait more than slack's 3 seconds time limit
    cli.chat_postMessage(channel='#general', text='I come from the future')
    return
from flask import Flask
from slackify import Slackify, request, text_block, Slack, ACK, OK, block_reply, respond
import os
import json
import main_time
from slackify.tasks import async_task

app = Flask(__name__)
slackify = Slackify(app=app)
cli = Slack(os.getenv('SLACK_API_TOKEN'))


@slackify.command
def hello():
    """Send hello message with question and yes no buttons"""
    YES = 'yes'
    NO = 'no'
    yes_no_buttons_block = {
        "type":
        "actions",
        "elements": [{
            "type": "button",
            "text": {
                "type": "plain_text",
                "emoji": True,
                "text": "Yes"
            },
            "style": "primary",
            "value": "i_like_bots",
            "action_id": YES
        }, {
Beispiel #5
0
import os
import random
import re

from flask import Flask
from slackify import (ACK, OK, Slackify, async_task, block_reply,
                      request, respond, text_block, Slack)


app = Flask(__name__)
slackify = Slackify(app=app)
cli = Slack(os.getenv('BOT_TOKEN'))


@slackify.command
def hello():
    YES = 'yes'
    NO = 'no'
    yes_no_buttons_block = {
        "type": "actions",
        "elements": [
            {
                "type": "button",
                "text": {
                    "type": "plain_text",
                    "emoji": True,
                    "text": "Yes"
                },
                "style": "primary",
                "value": "i_like_bots",
                "action_id": YES
Beispiel #6
0
from slackify import Flack, request, text_block, Slack, ACK
import json

app = Flack(__name__)
cli = Slack('xoxb-SECRET-TOKEN')


@app.command
def register():
    username_input_block = {
        "type": "input",
        "block_id": "username_block",
        "element": {
            "type": "plain_text_input",
            "placeholder": {
                "type": "plain_text",
                "text": "Enter your username"
            },
            "action_id": "username_value"
        },
        "label": {
            "type": "plain_text",
            "text": "👤 Username",
            "emoji": True
        }
    }
    password_input_block = {
        "type": "input",
        "block_id": "password_block",
        "element": {
            "type": "plain_text_input",