def _notify_slack_status_change(task, current_worker, slack_api_key, slack_channel, with_slack_link=True, with_user_mention=False): slack = OrchestraSlackService(slack_api_key) slack_statuses = { Task.Status.PROCESSING: 'Task has been picked up by a worker.', Task.Status.PENDING_REVIEW: 'Task is awaiting review.', Task.Status.REVIEWING: 'Task is under review.', Task.Status.POST_REVIEW_PROCESSING: 'Task was returned by reviewer.', Task.Status.COMPLETE: 'Task has been completed.', Task.Status.ABORTED: 'Task has been aborted.', } slack_username = getattr(current_worker, 'slack_username', None) worker_string = current_worker.user.username if current_worker else None if current_worker and slack_username and with_user_mention: user_id = slack.users.get_user_id(slack_username) worker_string += ' (<@{}|{}>)'.format(user_id, slack_username) slack_message = ('*{}*\n' '>>>' 'Current worker: {}' '{}').format( slack_statuses[task.status], worker_string, _task_information(task, with_slack_link=with_slack_link)) slack.chat.post_message(slack_channel, slack_message)
def __init__(self, token, allowed_team_ids=None, allowed_domains=None, allowed_channel_ids=None, allowed_channel_names=None, allowed_user_ids=None, allowed_user_names=None, allowed_commands=None, slack_api_key=None, **kwargs): """ Base configuration for the bot to validate messages. If a variable is None, all fields are allowed, otherwise each request will only be accepted if the request fields are contained in the whitelists. """ self.token = token self.slack = OrchestraSlackService(slack_api_key) self.whitelists = { 'team_id': allowed_team_ids, 'team_domain': allowed_domains, 'channel_id': allowed_channel_ids, 'channel_name': allowed_channel_names, 'user_id': allowed_user_ids, 'user_name': allowed_user_names, 'command': allowed_commands, } self.commands += ((r'help', 'help'), ) self.command_matchers = [(re.compile(pattern, re.IGNORECASE), command) for pattern, command in self.commands]
def _notify_slack_status_change(task, current_worker, slack_api_key, slack_channel, with_slack_link=True, with_user_mention=False, staffing_request_inquiry=None): slack = OrchestraSlackService(slack_api_key) auto_staff_method = ( StaffingRequestInquiry.CommunicationMethod.PREVIOUSLY_OPTED_IN) is_auto_staffed = (staffing_request_inquiry and staffing_request_inquiry.communication_method == auto_staff_method.value) processing_status_message = ( 'Task has been auto-staffed to a worker.' if is_auto_staffed else 'Task has been picked up by a worker.') slack_statuses = { Task.Status.PROCESSING: processing_status_message, Task.Status.PENDING_REVIEW: 'Task is awaiting review.', Task.Status.REVIEWING: 'Task is under review.', Task.Status.POST_REVIEW_PROCESSING: 'Task was returned by reviewer.', Task.Status.COMPLETE: 'Task has been completed.', Task.Status.ABORTED: 'Task has been aborted.', } worker_string = current_worker.user.username if current_worker else None slack_user_id = current_worker.slack_user_id if current_worker else None if slack_user_id and with_user_mention: worker_string += ' (<@{}>)'.format(slack_user_id) slack_message = ('*{}*\n' '>>>' 'Current worker: {}' '{}').format(slack_statuses[task.status], worker_string, _task_information( task, with_slack_link=with_slack_link)) slack.chat.post_message(slack_channel, slack_message)
def edit_slack_membership(project_id, username, action): slack = OrchestraSlackService() slack_user_id = slack.users.get_user_id(username) slack_group_id = Project.objects.get(id=project_id).slack_group_id if action == 'add': slack.groups.invite(slack_group_id, slack_user_id) elif action == 'remove': slack.groups.kick(slack_group_id, slack_user_id) else: raise Exception('Action not found.')
def message_internal_slack_group(slack_channel, slack_message): slack = OrchestraSlackService(settings.SLACK_INTERNAL_API_KEY) slack.chat.post_message(slack_channel, slack_message)
def message_experts_slack_group(slack_channel, slack_message): slack = OrchestraSlackService(settings.SLACK_EXPERTS_API_KEY) slack.chat.post_message(slack_channel, slack_message)