def test_document_3(self):
     input = {
         "type": "plain_text_input",
         "multiline": True,
         "dispatch_action_config": {"trigger_actions_on": ["on_character_entered"]},
     }
     self.assertDictEqual(input, PlainTextInputElement(**input).to_dict())
 def test_document_1(self):
     input = {
         "type": "plain_text_input",
         "action_id": "plain_input",
         "placeholder": {"type": "plain_text", "text": "Enter some plain text"},
     }
     self.assertDictEqual(input, PlainTextInputElement(**input).to_dict())
示例#3
0
async def shortcuts(request: Request):
    form = await request.form()
    payload = Payload.parse_raw(form['payload'])
    try:
        team_conf = TeamConf.get(payload.team.id)
    except TeamConf.DoesNotExist:
        return Response(status_code=HTTPStatus.BAD_REQUEST)
    client = WebClient(team_conf.access_token)
    if payload.callback_id == 'edit_emoji_set':
        emoji_set = team_conf.emoji_set
        # 登録できるemojiは3つまで
        if emoji_set is None:
            emoji_count = 0
            external_input = 3
            blocks = []
        else:
            emoji_count = len(emoji_set)
            external_input = 3 - emoji_count
            blocks = [
                InputBlock(
                    block_id=f'emoji_{index}',
                    label=f':{item}:',
                    element=PlainTextInputElement(
                        action_id=f'emoji_{index}',
                        initial_value=item,
                        placeholder=':atodeyomu:',
                    ),
                    optional=True,
                ) for index, item in enumerate(emoji_set)
            ]
        blocks += [
            InputBlock(
                block_id=f'emoji_{emoji_count + i}',
                label=f'追加するemoji({emoji_count + i}つ目)',
                element=PlainTextInputElement(action_id=f'emoji_{emoji_count + i}', placeholder=':atodeyomu:'),
                optional=True,
            ) for i in range(external_input)
        ]
        view = View(title='emojiを追加する', type='modal', callback_id='edit_emoji_set', blocks=blocks, submit='送信')
        if payload.trigger_id:
            client.views_open(trigger_id=payload.trigger_id, view=view)
    return Response()
 def test_document_2(self):
     input = {
         "type": "plain_text_input",
         "action_id": "plain_input",
         "placeholder": {"type": "plain_text", "text": "Enter some plain text"},
         "initial_value": "TODO",
         "multiline": True,
         "min_length": 1,
         "max_length": 10,
     }
     self.assertDictEqual(input, PlainTextInputElement(**input).to_dict())
示例#5
0
 def test_invalid_type_value(self):
     modal_view = View(
         type="modallll",
         callback_id="modal-id",
         title=PlainTextObject(text="Awesome Modal"),
         submit=PlainTextObject(text="Submit"),
         close=PlainTextObject(text="Cancel"),
         blocks=[
             InputBlock(
                 block_id="b-id",
                 label=PlainTextObject(text="Input label"),
                 element=PlainTextInputElement(action_id="a-id"),
             ),
         ],
     )
     with self.assertRaises(SlackObjectFormationError):
         modal_view.validate_json()
示例#6
0
 def test_valid_construction(self):
     modal_view = View(
         type="modal",
         callback_id="modal-id",
         title=PlainTextObject(text="Awesome Modal"),
         submit=PlainTextObject(text="Submit"),
         close=PlainTextObject(text="Cancel"),
         blocks=[
             InputBlock(
                 block_id="b-id",
                 label=PlainTextObject(text="Input label"),
                 element=PlainTextInputElement(action_id="a-id"),
             ),
             InputBlock(
                 block_id="cb-id",
                 label=PlainTextObject(text="Label"),
                 element=CheckboxesElement(
                     action_id="a-cb-id",
                     options=[
                         Option(
                             text=PlainTextObject(
                                 text="*this is plain_text text*"),
                             value="v1",
                         ),
                         Option(
                             text=MarkdownTextObject(
                                 text="*this is mrkdwn text*"),
                             value="v2",
                         ),
                     ],
                 ),
             ),
             SectionBlock(
                 block_id="sb-id",
                 text=MarkdownTextObject(
                     text="This is a mrkdwn text section block."),
                 fields=[
                     PlainTextObject(text="*this is plain_text text*",
                                     emoji=True),
                     MarkdownTextObject(text="*this is mrkdwn text*"),
                     PlainTextObject(text="*this is plain_text text*",
                                     emoji=True),
                 ],
             ),
             DividerBlock(),
             SectionBlock(
                 block_id="rb-id",
                 text=MarkdownTextObject(
                     text=
                     "This is a section block with radio button accessory"),
                 accessory=RadioButtonsElement(
                     initial_option=Option(
                         text=PlainTextObject(text="Option 1"),
                         value="option 1",
                         description=PlainTextObject(
                             text="Description for option 1"),
                     ),
                     options=[
                         Option(
                             text=PlainTextObject(text="Option 1"),
                             value="option 1",
                             description=PlainTextObject(
                                 text="Description for option 1"),
                         ),
                         Option(
                             text=PlainTextObject(text="Option 2"),
                             value="option 2",
                             description=PlainTextObject(
                                 text="Description for option 2"),
                         ),
                     ],
                 ),
             ),
         ],
     )
     modal_view.validate_json()
示例#7
0
def handle_command(body: dict, ack: Ack, respond: Respond, client: WebClient,
                   logger: Logger) -> None:
    logger.info(body)
    ack(
        text="Accepted!",
        blocks=[
            SectionBlock(
                block_id="b",
                text=MarkdownTextObject(text=":white_check_mark: Accepted!"),
            )
        ],
    )

    respond(blocks=[
        SectionBlock(
            block_id="b",
            text=MarkdownTextObject(
                text="You can add a button alongside text in your message. "),
            accessory=ButtonElement(
                action_id="a",
                text=PlainTextObject(text="Button"),
                value="click_me_123",
            ),
        ),
    ])

    res = client.views_open(
        trigger_id=body["trigger_id"],
        view=View(
            type="modal",
            callback_id="view-id",
            title=PlainTextObject(text="My App"),
            submit=PlainTextObject(text="Submit"),
            close=PlainTextObject(text="Cancel"),
            blocks=[
                InputBlock(
                    element=PlainTextInputElement(action_id="text"),
                    label=PlainTextObject(text="Label"),
                ),
                InputBlock(
                    block_id="es_b",
                    element=ExternalDataSelectElement(
                        action_id="es_a",
                        placeholder=PlainTextObject(text="Select an item"),
                        min_query_length=0,
                    ),
                    label=PlainTextObject(text="Search"),
                ),
                InputBlock(
                    block_id="mes_b",
                    element=ExternalDataMultiSelectElement(
                        action_id="mes_a",
                        placeholder=PlainTextObject(text="Select an item"),
                        min_query_length=0,
                    ),
                    label=PlainTextObject(text="Search (multi)"),
                ),
            ],
        ),
    )
    logger.info(res)