def to_dict(self) -> dict:
     json = super().to_dict()
     if isinstance(self.options[0], OptionGroup):
         json["option_groups"] = extract_json(self.options, "action")
     else:
         json["options"] = extract_json(self.options, "action")
     return json
示例#2
0
 def to_dict(self) -> dict:  # skipcq: PYL-W0221
     json = super().to_dict()
     if self.fields is not None:
         json["fields"] = extract_json(self.fields)
     if self.markdown_in:
         json["mrkdwn_in"] = self.markdown_in
     return json
示例#3
0
 def to_dict(self) -> dict:
     json = super().to_dict()
     if self.selected_option is not None:
         # this is a special case for ExternalActionSelectElement - in that case,
         # you pass the initial value of the selector as a selected_options array
         json["selected_options"] = extract_json([self.selected_option], "action")
     return json
 def to_dict(self) -> dict:  # skipcq: PYL-W0221
     json = super().to_dict()
     if len(self.text) > 40000:
         LOGGER.error(
             "Messages over 40,000 characters are automatically truncated by Slack"
         )
     if self.text and self.blocks:
         #  Slack doesn't render the text property if there are blocks, so:
         LOGGER.info(
             "text attribute is treated as fallback text if blocks are attached to "
             "a message - insert text as a new SectionBlock if you want it to be "
             "displayed ")
     json["attachments"] = extract_json(self.attachments)
     json["blocks"] = extract_json(self.blocks)
     json["mrkdwn"] = self.markdown
     return json
示例#5
0
 def send(self, channel: Union[Channel, str], text: str, **kwargs):
     channel_id = id_for_channel(channel)
     if 'attachments' in kwargs and kwargs['attachments'] is not None:
         kwargs['attachments'] = extract_json(kwargs['attachments'])
     if 'blocks' in kwargs and kwargs['blocks'] is not None:
         kwargs['blocks'] = extract_json(kwargs['blocks'])
     if 'ephemeral_user' in kwargs and kwargs['ephemeral_user'] is not None:
         ephemeral_user_id = id_for_user(kwargs['ephemeral_user'])
         del kwargs['ephemeral_user']
         return LowLevelSlackClient.get_instance(
         ).web_client.chat_postEphemeral(channel=channel_id,
                                         user=ephemeral_user_id,
                                         text=text,
                                         **kwargs)
     else:
         return LowLevelSlackClient.get_instance(
         ).web_client.chat_postMessage(channel=channel_id,
                                       text=text,
                                       **kwargs)
示例#6
0
 def to_dict(self) -> dict:  # skipcq: PYL-W0221
     json = super().to_dict()
     if len(self.text) > 40000:
         LOGGER.error(
             "Messages over 40,000 characters are automatically truncated by Slack"
         )
     # The following limitation used to be true in the past.
     # As of Feb 2021, having both is recommended
     # -----------------
     # if self.text and self.blocks:
     #     #  Slack doesn't render the text property if there are blocks, so:
     #     LOGGER.info(q
     #         "text attribute is treated as fallback text if blocks are attached to "
     #         "a message - insert text as a new SectionBlock if you want it to be "
     #         "displayed "
     #     )
     json["attachments"] = extract_json(self.attachments)
     json["blocks"] = extract_json(self.blocks)
     json["mrkdwn"] = self.markdown
     return json
 def to_dict(self) -> dict:  # skipcq: PYL-W0221
     self.validate_json()
     json = {
         "title": self._title,
         "callback_id": self._callback_id,
         "elements": extract_json(self._elements),
         "notify_on_cancel": self._notify_on_cancel,
     }
     if self._submit_label is not None:
         json["submit_label"] = self._submit_label
     if self._state is not None:
         json["state"] = self._state
     return json
 def to_dict(self) -> dict:  # skipcq: PYL-W0221
     json = super().to_dict()
     if self.data_source == "external":
         if isinstance(self.value, Option):
             json["selected_options"] = extract_json([self.value], "dialog")
         elif self.value is not None:
             json["selected_options"] = Option.from_single_value(self.value)
     else:
         if isinstance(self.value, Option):
             json["value"] = self.value.value
         elif self.value is not None:
             json["value"] = self.value
     return json
示例#9
0
 def test_from_list_of_json_objects(self):
     json_objects = [
         PlainTextObject.from_str("foo"),
         MarkdownTextObject.from_str("bar"),
     ]
     output = extract_json(json_objects)
     expected = {
         "result": [
             {"type": "plain_text", "text": "foo", "emoji": True},
             {"type": "mrkdwn", "text": "bar"},
         ]
     }
     self.assertDictEqual(expected, {"result": output})
示例#10
0
 def to_dict(self) -> dict:
     json = super().to_dict()
     json["actions"] = extract_json(self.actions)
     return json
示例#11
0
 def to_dict(self) -> dict:
     json = super().to_dict()
     json.update({"blocks": extract_json(self.blocks)})
     del json["fields"]  # cannot supply fields and blocks at the same time
     return json
示例#12
0
 def to_dict(self) -> dict:
     json = super().to_dict()
     if self.confirm is not None:
         json["confirm"] = extract_json(self.confirm, "action")
     return json
示例#13
0
 def test_from_single_json_object(self):
     single_json_object = PlainTextObject.from_str("foo")
     output = extract_json(single_json_object)
     expected = {"result": {"type": "plain_text", "text": "foo", "emoji": True}}
     self.assertDictEqual(expected, {"result": output})