示例#1
0
 async def __call__(
     self,
     text: Union[str, dict] = "",
     blocks: Optional[Sequence[Union[dict, Block]]] = None,
     attachments: Optional[Sequence[Union[dict, Attachment]]] = None,
     response_type: Optional[str] = None,
     replace_original: Optional[bool] = None,
     delete_original: Optional[bool] = None,
 ) -> WebhookResponse:
     if self.response_url is not None:
         client = AsyncWebhookClient(self.response_url)
         text_or_whole_response: Union[str, dict] = text
         if isinstance(text_or_whole_response, str):
             message = _build_message(
                 text=text,
                 blocks=blocks,
                 attachments=attachments,
                 response_type=response_type,
                 replace_original=replace_original,
                 delete_original=delete_original,
             )
             return await client.send_dict(message)
         elif isinstance(text_or_whole_response, dict):
             whole_response: dict = text_or_whole_response
             message = _build_message(**whole_response)
             return await client.send_dict(message)
         else:
             raise ValueError(f"The arg is unexpected type ({type(text)})")
     else:
         raise ValueError(
             "respond is unsupported here as there is no response_url")
 def test_build_message_delete_original(self):
     message = _build_message(delete_original=True)
     assert message is not None
 def test_build_message_response_type(self):
     message = _build_message(response_type="in_channel")
     assert message is not None
 def test_build_message_replace_original(self):
     message = _build_message(replace_original=True)
     assert message is not None
 def test_build_message_attachments(self):
     message = _build_message(attachments=[{}])
     assert message is not None
 def test_build_message_blocks2(self):
     message = _build_message(blocks=[DividerBlock(block_id="foo")])
     assert message is not None
     assert isinstance(message["blocks"][0], dict)
     assert message["blocks"][0]["block_id"] == "foo"
 def test_build_message_blocks(self):
     message = _build_message(blocks=[{"type": "divider"}])
     assert message is not None
 def test_build_message_text(self):
     message = _build_message(text="Hello!")
     assert message is not None
 def test_build_message_empty(self):
     message = _build_message()
     assert message is not None