コード例 #1
0
ファイル: test_slack.py プロジェクト: zhangyangisme/slackify
def test_text_block():
    assert text_block('message') == {
        "type": "section",
        "text": {
            "type": 'mrkdwn',
            "text": 'message'
        }
    }

    assert text_block('message', markdown=False) == {
        "type": "section",
        "text": {
            "type": 'plain_text',
            "text": 'message'
        }
    }
コード例 #2
0
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
        }, {
            "type": "button",
            "text": {
                "type": "plain_text",
                "emoji": True,
                "text": "No"
            },
            "style": "danger",
            "value": "i_dont_like_bots",
            "action_id": NO
        }]
    }
    blocks = [text_block('Do you like Bots?'), yes_no_buttons_block]
    return block_reply(blocks)
コード例 #3
0
def register_callback():
    action = json.loads(request.form["payload"])
    response = action['view']['state']['values']
    text_blok = text_block(
        f':heavy_check_mark: You are now registered.\nForm payload:\n```{response}```'
    )
    send_message(cli, [text_blok], action['user']['id'])
    return ACK
コード例 #4
0
def register_callback():
    """You may ask here, why DON'T we also use the response_url as we did in actions.py?

    Well, slack doesn't include a response_url on view_submission payload.
    https://api.slack.com/surfaces/modals/using#handling_submissions#modal_response_url
    From that link we understand we have 3 options:
    - Use the WebClient API
    - Use a webhook,
    - Include a `conversation_select` block in your modal view.

    We'll stick to the first one as it is the easiest for demostration purposes. But
    read the link to respond by any of the other options.
    """
    action = json.loads(request.form["payload"])
    response = action['view']['state']['values']
    text_blok = text_block(
        f':heavy_check_mark: You are now registered.\nPayload:\n```{response}```'
    )
    send_message(cli, [text_blok], action['user']['id'])
    return ACK
コード例 #5
0
def no(payload):
    """If a user clicks no on the hello message, execute this callback"""
    text_blok = text_block('Boo! You are so boring :thumbsdown:')
    respond(payload['response_url'], {'blocks': [text_blok]})
    return OK
コード例 #6
0
def yes(payload):
    """If a user clicks yes on the message above, execute this callback"""
    text_blok = text_block('Super! I do too :thumbsup:')
    respond(payload['response_url'], {'blocks': [text_blok]})
    return OK
コード例 #7
0
ファイル: full.py プロジェクト: fakegit/slackify
def no(action):
    text_blok = text_block('Boo! You are so boring :thumbsdown:')
    respond(action['response_url'], {'blocks': [text_blok]})
    return OK
コード例 #8
0
ファイル: full.py プロジェクト: fakegit/slackify
def yes(action):
    text_blok = text_block('Super! I do too :thumbsup:')
    respond(action['response_url'], {'blocks': [text_blok]})
    return OK
コード例 #9
0
ファイル: full.py プロジェクト: fakegit/slackify
def dice_roll(payload):
    dice_value = random.randint(1, 6)
    msg = f'🎲 {dice_value}'
    send_message(cli, blocks=[text_block(msg)], user_id=payload['user']['id'])
    return ACK
コード例 #10
0
ファイル: full.py プロジェクト: fakegit/slackify
def register_callback(payload):
    response = payload['view']['state']['values']
    text_blok = text_block(f':heavy_check_mark: You are now registered.\nForm payload:\n```{response}```')
    send_message(cli, [text_blok], payload['user']['id'])
    return ACK
コード例 #11
0
ファイル: full.py プロジェクト: zhangyangisme/slackify
def no():
    action = json.loads(request.form["payload"])
    text_blok = text_block('Boo! You are so boring :thumbsdown:')
    respond(action['response_url'], {'blocks': [text_blok]})
    return OK
コード例 #12
0
ファイル: full.py プロジェクト: zhangyangisme/slackify
def yes():
    action = json.loads(request.form["payload"])
    text_blok = text_block('Super! I do too :thumbsup:')
    respond(action['response_url'], {'blocks': [text_blok]})
    return OK
コード例 #13
0
ファイル: full.py プロジェクト: zhangyangisme/slackify
def dice_roll():
    payload = json.loads(request.form['payload'])
    dice_value = random.randint(1, 6)
    msg = f'🎲 {dice_value}'
    send_message(cli, blocks=[text_block(msg)], user_id=payload['user']['id'])
    return ACK
コード例 #14
0
def dice_roll(payload):
    """Roll a virtual dice to give a pseudo-random number"""
    dice_value = random.randint(1, 6)
    msg = f'🎲 {dice_value}'
    send_message(cli, blocks=[text_block(msg)], user_id=payload['user']['id'])
    return ACK