|
23 | 23 | ImageElement, |
24 | 24 | InputInteractiveElement, |
25 | 25 | InteractiveElement, |
| 26 | + OverflowMenuElement, |
26 | 27 | RichTextElement, |
27 | 28 | UrlSourceElement, |
28 | 29 | ) |
@@ -118,6 +119,8 @@ def parse(cls, block: Union[dict, "Block"]) -> Optional["Block"]: |
118 | 119 | return ContainerBlock(**block) |
119 | 120 | elif type == CarouselBlock.type: |
120 | 121 | return CarouselBlock(**block) |
| 122 | + elif type == AuthProviderBlock.type: |
| 123 | + return AuthProviderBlock(**block) |
121 | 124 | else: |
122 | 125 | cls.logger.warning(f"Unknown block detected and skipped ({block})") |
123 | 126 | return None |
@@ -1157,3 +1160,143 @@ def _validate_elements_present(self): |
1157 | 1160 | @JsonValidator(f"elements attribute cannot exceed {elements_max_length} cards") |
1158 | 1161 | def _validate_elements_length(self): |
1159 | 1162 | return self.elements is None or len(self.elements) <= self.elements_max_length |
| 1163 | + |
| 1164 | + |
| 1165 | +class AuthProviderBlock(Block): |
| 1166 | + type = "auth_provider" |
| 1167 | + value_max_length = 150 |
| 1168 | + name_max_length = 75 |
| 1169 | + description_max_length = 150 |
| 1170 | + connected_identity_max_length = 75 |
| 1171 | + connected_context_max_length = 75 |
| 1172 | + url_max_length = 3000 |
| 1173 | + |
| 1174 | + @property |
| 1175 | + def attributes(self) -> Set[str]: # type: ignore[override] |
| 1176 | + return super().attributes.union( |
| 1177 | + { |
| 1178 | + "value", |
| 1179 | + "name", |
| 1180 | + "is_connected", |
| 1181 | + "description", |
| 1182 | + "icon_url", |
| 1183 | + "auth_url", |
| 1184 | + "disconnect_url", |
| 1185 | + "connected_identity", |
| 1186 | + "connected_context", |
| 1187 | + "accessory", |
| 1188 | + "fallback", |
| 1189 | + } |
| 1190 | + ) |
| 1191 | + |
| 1192 | + def __init__( |
| 1193 | + self, |
| 1194 | + *, |
| 1195 | + value: str, |
| 1196 | + name: Union[str, dict, PlainTextObject], |
| 1197 | + is_connected: bool, |
| 1198 | + description: Optional[Union[str, dict, PlainTextObject]] = None, |
| 1199 | + icon_url: Optional[str] = None, |
| 1200 | + auth_url: Optional[str] = None, |
| 1201 | + disconnect_url: Optional[str] = None, |
| 1202 | + connected_identity: Optional[Union[str, dict, PlainTextObject]] = None, |
| 1203 | + connected_context: Optional[Union[str, dict, PlainTextObject]] = None, |
| 1204 | + accessory: Optional[Union[dict, OverflowMenuElement]] = None, |
| 1205 | + fallback: Optional[Sequence[Union[dict, Block]]] = None, |
| 1206 | + block_id: Optional[str] = None, |
| 1207 | + **others: dict, |
| 1208 | + ): |
| 1209 | + """Displays authentication provider information, including its icon, name, and connection state. |
| 1210 | +
|
| 1211 | + https://docs.slack.dev/reference/block-kit/blocks/auth-provider-block |
| 1212 | +
|
| 1213 | + Args: |
| 1214 | + value (required): A unique identifier for this provider within the app. Included in interaction |
| 1215 | + payloads and used to derive the connect button's action_id as auth_provider_connect_<value>. |
| 1216 | + Maximum length for this field is 150 characters. |
| 1217 | + name (required): The provider's display name, in the form of a plain_text text object. |
| 1218 | + Maximum length for the text in this field is 75 characters. |
| 1219 | + is_connected (required): Whether the user is connected to this provider. Slack stores this value |
| 1220 | + for the user, so it must be set explicitly. |
| 1221 | + description: A description of the provider, in the form of a plain_text text object. |
| 1222 | + Maximum length for the text in this field is 150 characters. |
| 1223 | + icon_url: An HTTPS URL for the provider's icon. Defaults to the app's avatar if omitted. |
| 1224 | + Maximum length for this field is 3000 characters. |
| 1225 | + auth_url: The HTTPS URL opened when the user clicks Connect. Its host must be listed in the |
| 1226 | + app manifest's features.user_connections.auth_hosts, or be a subdomain of one. |
| 1227 | + Maximum length for this field is 3000 characters. |
| 1228 | + disconnect_url: The HTTPS URL opened when the user clicks Disconnect. Its host must be listed in |
| 1229 | + the app manifest's features.user_connections.auth_hosts, or be a subdomain of one. |
| 1230 | + Maximum length for this field is 3000 characters. |
| 1231 | + connected_identity: The display name of the connected account, in the form of a plain_text text object. |
| 1232 | + Shown when is_connected is true. |
| 1233 | + Maximum length for the text in this field is 75 characters. |
| 1234 | + connected_context: Additional context about the connection, such as an organization or workspace name, |
| 1235 | + in the form of a plain_text text object. |
| 1236 | + Maximum length for the text in this field is 75 characters. |
| 1237 | + accessory: An overflow menu element shown when the user is connected. |
| 1238 | + fallback: A list of blocks rendered in place of this block by clients that don't support it. |
| 1239 | + block_id: A unique identifier for a block. If not specified, a block_id will be generated. |
| 1240 | + """ |
| 1241 | + super().__init__(type=self.type, block_id=block_id) |
| 1242 | + show_unknown_key_warning(self, others) |
| 1243 | + |
| 1244 | + self.value = value |
| 1245 | + self.name = TextObject.parse(name, default_type=PlainTextObject.type) |
| 1246 | + self.is_connected = is_connected |
| 1247 | + self.description = TextObject.parse(description, default_type=PlainTextObject.type) # type: ignore[arg-type] |
| 1248 | + self.icon_url = icon_url |
| 1249 | + self.auth_url = auth_url |
| 1250 | + self.disconnect_url = disconnect_url |
| 1251 | + self.connected_identity = TextObject.parse(connected_identity, default_type=PlainTextObject.type) # type: ignore[arg-type] |
| 1252 | + self.connected_context = TextObject.parse(connected_context, default_type=PlainTextObject.type) # type: ignore[arg-type] |
| 1253 | + self.accessory = BlockElement.parse(accessory) # type: ignore[arg-type] |
| 1254 | + self.fallback = Block.parse_all(fallback) if fallback is not None else None |
| 1255 | + |
| 1256 | + @JsonValidator("value attribute must be specified") |
| 1257 | + def _validate_value(self): |
| 1258 | + return self.value is not None and len(self.value) >= 1 |
| 1259 | + |
| 1260 | + @JsonValidator(f"value attribute cannot exceed {value_max_length} characters") |
| 1261 | + def _validate_value_length(self): |
| 1262 | + return self.value is None or len(self.value) <= self.value_max_length |
| 1263 | + |
| 1264 | + @JsonValidator("name attribute must be specified") |
| 1265 | + def _validate_name(self): |
| 1266 | + return self.name is not None |
| 1267 | + |
| 1268 | + @JsonValidator(f"name attribute cannot exceed {name_max_length} characters") |
| 1269 | + def _validate_name_length(self): |
| 1270 | + return self.name is None or len(self.name.text) <= self.name_max_length |
| 1271 | + |
| 1272 | + @JsonValidator("is_connected attribute must be specified") |
| 1273 | + def _validate_is_connected(self): |
| 1274 | + return self.is_connected is not None |
| 1275 | + |
| 1276 | + @JsonValidator(f"description attribute cannot exceed {description_max_length} characters") |
| 1277 | + def _validate_description_length(self): |
| 1278 | + return self.description is None or len(self.description.text) <= self.description_max_length |
| 1279 | + |
| 1280 | + @JsonValidator(f"connected_identity attribute cannot exceed {connected_identity_max_length} characters") |
| 1281 | + def _validate_connected_identity_length(self): |
| 1282 | + return self.connected_identity is None or len(self.connected_identity.text) <= self.connected_identity_max_length |
| 1283 | + |
| 1284 | + @JsonValidator(f"connected_context attribute cannot exceed {connected_context_max_length} characters") |
| 1285 | + def _validate_connected_context_length(self): |
| 1286 | + return self.connected_context is None or len(self.connected_context.text) <= self.connected_context_max_length |
| 1287 | + |
| 1288 | + @JsonValidator(f"icon_url attribute cannot exceed {url_max_length} characters") |
| 1289 | + def _validate_icon_url_length(self): |
| 1290 | + return self.icon_url is None or len(self.icon_url) <= self.url_max_length |
| 1291 | + |
| 1292 | + @JsonValidator(f"auth_url attribute cannot exceed {url_max_length} characters") |
| 1293 | + def _validate_auth_url_length(self): |
| 1294 | + return self.auth_url is None or len(self.auth_url) <= self.url_max_length |
| 1295 | + |
| 1296 | + @JsonValidator(f"disconnect_url attribute cannot exceed {url_max_length} characters") |
| 1297 | + def _validate_disconnect_url_length(self): |
| 1298 | + return self.disconnect_url is None or len(self.disconnect_url) <= self.url_max_length |
| 1299 | + |
| 1300 | + @JsonValidator("accessory attribute must be an overflow menu element") |
| 1301 | + def _validate_accessory(self): |
| 1302 | + return self.accessory is None or isinstance(self.accessory, OverflowMenuElement) |
0 commit comments