Mattermost Dispatcher¶
nautobot_chatops.dispatchers.mattermost
¶
Dispatcher implementation for sending content to Mattermost.
BadRequestException
¶
Bases: MMException
Malformed Request.
Driver
¶
Mattermost API Client.
Source code in nautobot_chatops/dispatchers/mattermost.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
__init__(options)
¶
Init the Mattermost Driver.
chat_post_ephemeral(channel_id, user_id, message=None, blocks=None)
¶
Post Ephemeral Message to Mattermost Channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel_id |
str
|
Mattermost ID for the Channel. |
required |
user_id |
str
|
Mattermost ID for the User. |
required |
message |
str
|
Text to add to the post. Defaults to None. |
None
|
blocks |
dict
|
Blocks to add to the post. Defaults to None. |
None
|
Source code in nautobot_chatops/dispatchers/mattermost.py
chat_post_message(channel_id, message=None, blocks=None, files=None, snippet=None)
¶
Post Message to Mattermost Channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel_id |
str
|
Mattermost ID for the Channel. |
required |
message |
str
|
Text to add to the post. Defaults to None. |
None
|
blocks |
dict
|
Blocks to add to the post. Defaults to None. |
None
|
files |
list
|
Local filepaths of files to send. Defaults to None. |
None
|
snippet |
[type]
|
Long text to upload and attach. Defaults to None. |
None
|
Source code in nautobot_chatops/dispatchers/mattermost.py
delete(endpoint)
¶
Delete object at endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
string
|
Endpoint to post delete to. |
required |
Source code in nautobot_chatops/dispatchers/mattermost.py
get(endpoint, params=None, raw=False)
¶
Get object from endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
str
|
Endpoint to get object from. |
required |
params |
str
|
Params to pass to the GET. Defaults to None. |
None
|
raw |
bool
|
Changes return to string. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict
|
Response from Mattermost API. Unless raw, which returns the string. |
Source code in nautobot_chatops/dispatchers/mattermost.py
open_dialog(trigger_id, view, dialog_url)
¶
Opens a Dialog in Mattermost.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trigger_id |
str
|
[description] |
required |
view |
[type]
|
[description] |
required |
dialog_url |
[type]
|
[description] |
required |
Source code in nautobot_chatops/dispatchers/mattermost.py
post(endpoint, params=None, data=None, multipart_formdata=None)
¶
Post object to endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
str
|
Endpoint to post object to. |
required |
params |
str
|
Optional params to pass to POST. Defaults to None. |
None
|
data |
dict
|
JSON dictionary to send to Mattermost. Defaults to None. |
None
|
multipart_formdata |
str
|
data to send using Multipart/formdata. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict
|
Response from Mattermost API. |
Source code in nautobot_chatops/dispatchers/mattermost.py
upload_file(channel_id, file)
¶
Uploads a file that can later be attached to a post.
Instead of passing the filepath, we instead expect a File Object or a byte string. This is to support images as well as snippets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel_id |
str
|
The channel ID to upload to. |
required |
file |
byte
|
The byte representation of the file. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict
|
Uploaded File. |
Source code in nautobot_chatops/dispatchers/mattermost.py
ForbiddenException
¶
Bases: MMException
Bot Unauthorized for api endpoint.
InternalServerErrorException
¶
Bases: MMException
Mattermost Server Error.
MMException
¶
MMRateLimit
¶
Bases: MMException
Mattermost responded with Rate Limited.
MattermostDispatcher
¶
Bases: Dispatcher
Dispatch messages and cards to Mattermost.
Source code in nautobot_chatops/dispatchers/mattermost.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
|
__init__(args, kwargs)
¶
Init a MattermostDispatcher.
Source code in nautobot_chatops/dispatchers/mattermost.py
actions_block(block_id, actions)
¶
Construct a block consisting of a set of action elements.
Source code in nautobot_chatops/dispatchers/mattermost.py
bold(text)
¶
command_response_header(command, subcommand, args, description='information', image_element=None)
¶
Construct a consistently forwarded header including the command that was issued.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
str
|
Primary command string |
required |
subcommand |
str
|
Secondary command string |
required |
args |
list
|
of tuples, either (arg_name, human_readable_value, literal_value) or (arg_name, literal_value) |
required |
description |
str
|
Short description of what information is contained in the response |
'information'
|
image_element |
dict
|
As constructed by self.image_element() |
None
|
Source code in nautobot_chatops/dispatchers/mattermost.py
delete_message(post_id)
¶
Delete a message that was previously sent.
Source code in nautobot_chatops/dispatchers/mattermost.py
image_element(url, alt_text='')
¶
Construct an image element that can be embedded in an attachment.
Source code in nautobot_chatops/dispatchers/mattermost.py
markdown_block(text)
¶
markdown_element(text)
¶
multi_input_dialog(command, sub_command, dialog_title, dialog_list)
¶
Provide several input fields on a single dialog.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
str
|
The top level command in use. (ex. net) |
required |
sub_command |
str
|
The command being invoked (ex. add-vlan) |
required |
dialog_title |
str
|
Title of the dialog box |
required |
dialog_list |
list
|
List of dictionaries containing the dialog parameters. See Example below. |
required |
Example
For a selection menu::
{
type: "select",
label: "label",
choices: [("display 1", "value1"), ("display 2", "value 2")],
default: ("display 1", "value1"),
confirm: False
}
For a text dialog::
{
type: "text",
label: "text displayed next to field"
default: "default-value",
optional: True
}
Dictionary Fields
- type: The type of object to create. Currently supported values: select, text
- label: A text descriptor that will be placed next to the field
- choices: A list of tuples which populates the choices in a dropdown selector
- default: (optional) Default choice of a select menu or initial value to put in a text field.
- confirm: (optional) If set to True, it will display a "Are you sure?" dialog upon submit.
- optional: (optional) If set to True, the field can is not required and will return an empty variable of NoneType if left blank.
Source code in nautobot_chatops/dispatchers/mattermost.py
platform_lookup(item_type, item_name)
classmethod
¶
Call out to the chat platform to look up, e.g., a specific user ID by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_type |
str
|
One of "organization", "channel", "user" |
required |
item_name |
str
|
Uniquely identifying name of the given item. |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
(str, None) |
Source code in nautobot_chatops/dispatchers/mattermost.py
prompt_for_text(action_id, help_text, label, title='Your attention please!')
¶
Prompt the user to enter freeform text into a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_id |
str
|
Identifier string to attach to the "submit" action. |
required |
help_text |
str
|
Markdown string to display as help text. |
required |
label |
str
|
Label text to display adjacent to the text field. |
required |
title |
str
|
Title to include on the modal dialog. |
'Your attention please!'
|
Source code in nautobot_chatops/dispatchers/mattermost.py
prompt_from_menu(action_id, help_text, choices, default=(None, None), confirm=False, offset=0)
¶
Prompt the user for a selection from a menu.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_id |
str
|
Identifier string to attach to the "submit" action. |
required |
help_text |
str
|
Markdown string to display as help text. |
required |
choices |
list
|
List of (display, value) tuples. |
required |
default |
tuple
|
Default (display, value) to pre-select. |
(None, None)
|
confirm |
bool
|
If True, prompt the user to confirm their selection (if the platform supports this). |
False
|
offset |
int
|
Used for apps that have a menu selection display limit. |
0
|
Source code in nautobot_chatops/dispatchers/mattermost.py
select_element(action_id, choices)
¶
Construct a basic selection menu with the given choices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_id |
str
|
Identifying string to associate with this element |
required |
choices |
list
|
List of (display, value) tuples |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict
|
select element |
Source code in nautobot_chatops/dispatchers/mattermost.py
select_element_interactive(action_id, choices, default=(None, None), confirm=False, optional=False)
¶
Construct a basic selection menu for a dialog with the given choices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_id |
str
|
Identifying string to associate with this element |
required |
choices |
list
|
List of (display, value) tuples |
required |
default |
tuple
|
Default (display, value) to preselect |
(None, None)
|
confirm |
bool
|
If true (and the platform supports it), prompt the user to confirm their selection |
False
|
optional |
bool
|
If set to True, the field will return NoneType is not specified. |
False
|
Returns:
Name | Type | Description |
---|---|---|
data |
dict
|
select element |
Source code in nautobot_chatops/dispatchers/mattermost.py
send_blocks(blocks, callback_id=None, modal=False, ephemeral=None, title='Your attention please!')
¶
Send a series of formatting blocks to the user/channel specified by the context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blocks |
list
|
List of block contents as constructed by other dispatcher functions. |
required |
callback_id |
str
|
Callback ID string such as "command subcommand arg1 arg2". Required if |
None
|
modal |
bool
|
Whether to send this as a modal dialog rather than an inline block. |
False
|
ephemeral |
bool
|
Whether to send this as an ephemeral message (only visible to the targeted user). |
None
|
title |
str
|
Title to include on a modal dialog. |
'Your attention please!'
|
Source code in nautobot_chatops/dispatchers/mattermost.py
send_busy_indicator()
¶
Send a "typing" indicator to show that work is in progress.
send_error(message)
¶
Send an error message to the user/channel specified by the context.
send_exception(exception)
¶
Try to report an exception to the user.
Source code in nautobot_chatops/dispatchers/mattermost.py
send_image(image_path)
¶
Send an image as a file upload.
Source code in nautobot_chatops/dispatchers/mattermost.py
send_markdown(message, ephemeral=None)
¶
Send a Markdown-formatted text message to the user/channel specified by the context.
Source code in nautobot_chatops/dispatchers/mattermost.py
send_snippet(text, title=None, ephemeral=None)
¶
Send a longer chunk of text as a file snippet.
Source code in nautobot_chatops/dispatchers/mattermost.py
send_warning(message)
¶
Send a warning message to the user/channel specified by the context.
text_element(text)
¶
MethodNotAllowedException
¶
Bases: MMException
Endpoint does not allow used method.
NotAcceptableException
¶
Bases: MMException
Invalid Content Type for Endpoint.
NotFoundException
¶
Bases: MMException
Endpoint does not exist.
ServiceUnavailableException
¶
Bases: MMException
Mattermost API is currently in maintenance mode.
UnauthorizedException
¶
Bases: MMException
Invalid Personal Access Token.
UnsupportedMediaTypeException
¶
Bases: MMException
Attempting to POST data in incorrect format.
error_report(function)
¶
Wrapper to catch api errors and raise appropriate Exceptions.