Exemplo n.º 1
0
def make_modal(
    state: SlackState,
    title: Union[str, Text],
    blocks: List[Block],
    action_id: Optional[str] = None,
    value: Optional[str] = None,
    metadata: Optional[dict] = {},
    submit: Optional[Union[Text, str]] = "Confirm",
    close: Optional[Union[Text, str]] = "Cancel",
):
    private_metadata = {
        **get_modal_metadata(state),
        "channel_id": state.channel.id,
        "action_id": action_id,
        "value": value,
        "ts": state.ts,
        "thread_ts": state.thread_ts,
        **metadata,
    }

    return {
        "type": "modal",
        "title": Text.to_text(title, force_plaintext=True)._resolve(),
        "submit": Text.to_text(submit, force_plaintext=True)._resolve(),
        "close": Text.to_text(close, force_plaintext=True)._resolve(),
        "blocks": repr(blocks),
        "private_metadata": json.dumps(private_metadata),
    }
Exemplo n.º 2
0
def test_basic_section_fields() -> None:
    block = SectionBlock(
        "Test:",
        fields=[Text(text='foo', type_=TextType.PLAINTEXT),
                Text(text='bar')],
        block_id="fake_block_id")
    with open("test/samples/section_block_fields.json", "r") as expected:
        assert repr(block) == expected.read()
Exemplo n.º 3
0
def process_leodagan(state, message):
    texts_to_test = find_code_blocks(message)

    blocks = []
    for text in texts_to_test:
        leodagan_result = launch_leodagan(text).decode("utf-8")
        if not leodagan_result:
            leodagan_result = "La netiquette est conforme."
        blocks.append(SectionBlock(Text(f"```{leodagan_result}```")))

    if blocks:
        send_message(state, text="Léodagan report", blocks=repr(blocks))
Exemplo n.º 4
0
def test_basic_context_block() -> None:
    block = ContextBlock(elements=[Text("Hello, world!")],
                         block_id="fake_block_id")
    with open("test/samples/context_block_text_only.json", "r") as expected:
        assert expected.read() == repr(block)
Exemplo n.º 5
0
 def add_product(self, name: str, url: str, arrival_type: str) -> None:
     text = Text(text="%s!!!\n\n> <%s|%s>" % (arrival_type, url, name))
     self.blocks.append(SectionBlock(text=text))
Exemplo n.º 6
0
def _iter_triage(t):
    fields = ['*start_date*', '*end_date*', t.start_date, t.end_date]
    header = SectionBlock(text=t.title, fields=[Text(f)._resolve() for f in fields])
    yield header
    yield from t.currently_failing
    yield from t.eventually_succeeded