def alert_done(name, message_url): """ Handle a new star being added to a message. """ message = "This graphic, {}, is completed: {}".format(name, message_url) sc_bot.api_call( "chat.postMessage", channel=SHARE_CHANNEL_ID, text=message, )
def assignment_made(payload): """ Handle a new assignment made via the selection menu. """ # Parse the payload selection = payload["actions"][0]["selected_options"][0]["value"] channel_id = payload["channel"]["id"] message_ts = payload["message_ts"] # Recreate original message message = payload["original_message"] text = message["text"] attachments = message["attachments"] # Update assignment selection attachments[1]["actions"][0]["selected_options"] = [{ "text": "<@%s>" % selection, "value": "%s" % selection }] # Add status dropdown if it's not there if (len(attachments) < 3): status_types = [{ "value": key, "text": REQUEST_STATUSES[key] } for key in REQUEST_STATUSES.keys()] status_selection = { "title": "Status", "fallback": "Choose a status", "callback_id": "status_change", "actions": [{ "name": "status", "text": "Set a status...", "type": "select", "options": status_types, "selected_options": [status_types[0]] }] } attachments.append(status_selection) # Update original message with changes sc_bot.api_call("chat.update", channel=channel_id, ts=message_ts, text=text, attachments=attachments)
def new_request(trigger_id, text=""): """ Create and serve a new graphic dialog box. """ # Create the options list types = [{ "value": key, "label": REQUEST_TYPES[key] } for key in REQUEST_TYPES.keys()] # Create the form message = { "callback_id": "request_made", "title": "Request A Graphic", "submit_label": "Request", "elements": [ { "type": "select", "label": "Type", "name": "type", "options": types }, { "type": "text", "label": "Story", "name": "story", "placeholder": "What story is this graphic for?" }, { "type": "textarea", "label": "Description", "name": "description", "placeholder": "Describe the graphic you envision.", "value": text } ] } # Open the dialog box sc_bot.api_call( "dialog.open", dialog=message, trigger_id=trigger_id )
def status_change(payload): """ Handle a new status change made via the selection menu. """ selection = payload["actions"][0]["selected_options"][0]["value"] channel_id = payload["channel"]["id"] message_ts = payload["message_ts"] message = payload["original_message"] text = message["text"] attachments = message["attachments"] # Update assignment selection attachments[2]["actions"][0]["selected_options"] = [{ "text": REQUEST_STATUSES[selection], "value": selection }] sc_bot.api_call("chat.update", channel=channel_id, ts=message_ts, text=text, attachments=attachments) # Create a log of assignments assignment_log = "{user} changed the status to {status}".format( user=payload["user"]["name"], status=REQUEST_STATUSES[selection]) sc_bot.api_call( "chat.postMessage", channel=channel_id, thread_ts=message_ts, text=assignment_log, ) # Pin/Unpin depending on status if (selection == "finished"): sc_bot.api_call("pins.remove", channel=REQUEST_CHANNEL_ID, timestamp=message_ts) else: sc_bot.api_call("pins.add", channel=REQUEST_CHANNEL_ID, timestamp=message_ts)
def request_made(payload): """ Handle a new request being submitted. """ # Parse payload username = payload["user"]["name"] user_id = payload["user"]["id"] channel_id = payload["channel"]["id"] submission = payload["submission"] # Create message text = "*\"{story}\"* {type} Request".format( story=submission["story"], type=REQUEST_TYPES[submission["type"]]) attachments = [{ "author_name": username, "text": submission["description"], "fields": [ { "title": "Type", "value": REQUEST_TYPES[submission["type"]], "short": True }, { "title": "Story", "value": submission["story"], "short": True }, ], }, { "text": "Assigned To", "attachment_type": "default", "callback_id": "assignment_made", "actions": [{ "name": "developers", "text": "Pick a developer...", "type": "select", "data_source": "users" }] }] # Post message to channel and retrieve response resp = sc_bot.api_call("chat.postMessage", channel=REQUEST_CHANNEL_ID, text=text, attachments=attachments) # Pin new requests message_ts = resp["message"]["ts"] sc_bot.api_call("pins.add", channel=REQUEST_CHANNEL_ID, timestamp=message_ts) # Confirm to user that the request was made confirmation = "Your request for a *{type}* graphic for the story" confirmation += " *\"{story}\"* has been made." confirmation += " You can track its progress in <#{channel}>." confirmation = confirmation.format(type=REQUEST_TYPES[submission["type"]], story=submission["story"], channel=REQUEST_CHANNEL_ID) sc_bot.api_call("chat.postEphemeral", text=confirmation, channel=channel_id, user=user_id)