def run(self, params={}):
        team_name = params.get(Input.TEAM_NAME, "")

        # The end of this filters for only MS Team enabled Teams
        teams = get_teams_from_microsoft(self.logger, self.connection,
                                         team_name, False)

        clean_teams = []
        for team in teams:
            clean_teams.append(remove_null_and_clean(team))

        return {Output.TEAMS: clean_teams}
示例#2
0
    def run(self, params={}):
        team_name = params.get(Input.TEAM_NAME)
        channel_name = params.get(Input.CHANNEL_NAME)
        message = params.get(Input.MESSAGE_CONTENT)

        teams = get_teams_from_microsoft(self.logger, self.connection, team_name)
        team_id = teams[0].get("id")
        channels = get_channels_from_microsoft(self.logger, self.connection, team_id, channel_name)
        channel_id = channels[0].get("id")

        message = send_html_message(self.logger, self.connection, message, team_id, channel_id)

        clean_message = remove_null_and_clean(message)

        return {Output.MESSAGE: clean_message}
示例#3
0
    def run(self, params={}):
        group_name = params.get(Input.GROUP_NAME)
        group_description = params.get(Input.GROUP_DESCRIPTION)
        mail_nickname = params.get(Input.MAIL_NICKNAME)
        mail_enabled = params.get(Input.MAIL_ENABLED)
        owners = params.get(Input.OWNERS)
        members = params.get(Input.MEMBERS)

        group_result = create_group(self.logger, self.connection, group_name,
                                    group_description, mail_nickname,
                                    mail_enabled, owners, members)

        group_id = group_result.get("id")

        enable_teams_for_group(self.logger, self.connection, group_id)

        return {Output.GROUP: remove_null_and_clean(group_result)}
示例#4
0
    def run(self, params={}):
        team_name = params.get(Input.TEAM_NAME)
        channel_name = params.get(Input.CHANNEL_NAME)

        team_array = get_teams_from_microsoft(self.logger, self.connection,
                                              team_name)
        team = team_array[0]

        team_id = team.get("id")

        channels = get_channels_from_microsoft(self.logger, self.connection,
                                               team_id, channel_name)
        clean_channels = []
        for channel in channels:
            clean_channels.append(remove_null_and_clean(channel))

        return {Output.CHANNELS: clean_channels}
示例#5
0
    def run(self, params={}):
        team_guid = params.get(Input.TEAM_GUID)
        channel_guid = params.get(Input.CHANNEL_GUID)
        is_html = params.get(Input.IS_HTML)
        message_content = params.get(Input.MESSAGE)

        if is_html:
            message = send_html_message(self.logger, self.connection,
                                        message_content, team_guid,
                                        channel_guid)
        else:
            message = send_message(self.logger, self.connection,
                                   message_content, team_guid, channel_guid)

        clean_message = remove_null_and_clean(message)

        return {Output.MESSAGE: clean_message}
示例#6
0
    def run(self, params={}):
        message = params.get(Input.MESSAGE_CONTENT)

        teams = get_teams_from_microsoft(self.logger, self.connection,
                                         params.get(Input.TEAM_NAME))
        team_id = teams[0].get("id")
        channels = get_channels_from_microsoft(self.logger, self.connection,
                                               team_id,
                                               params.get(Input.CHANNEL_NAME))

        message = send_html_message(self.logger,
                                    self.connection,
                                    message,
                                    team_id,
                                    channels[0].get("id"),
                                    thread_id=params.get(
                                        Input.THREAD_ID, None))

        return {Output.MESSAGE: remove_null_and_clean(message)}
示例#7
0
    def run(self, params={}):
        """Run the trigger"""
        team_name = params.get(Input.TEAM_NAME)
        channel_name = params.get(Input.CHANNEL_NAME)
        message_content = params.get(Input.MESSAGE_CONTENT)

        # Check for valid regex
        compiled_message_content = self.compile_message_content(
            message_content)

        # Setup the messages endpoint
        messages_endpoint = self.setup_endpoint(channel_name, team_name)

        # Get our initial set of messages
        sorted_messages = self.get_sorted_messages(messages_endpoint)

        # Get our most recent message date:
        try:
            last_time_we_checked = maya.parse(
                sorted_messages[0].get("createdDateTime"))
        except Exception as e:
            raise PluginException(PluginException.Preset.INVALID_JSON) from e

        time.sleep(
            1
        )  # Make sure we don't kill the API. It's limited to 3 calls a second

        while True:
            # Get messages
            sorted_messages = self.get_sorted_messages(messages_endpoint)
            most_recent_message_time = maya.parse(
                sorted_messages[0].get("createdDateTime"))

            if most_recent_message_time > last_time_we_checked:  # We have new messages
                self.logger.info("New messages found.")
                temp_time = most_recent_message_time

                for message in sorted_messages:  # For each new message
                    message = remove_null_and_clean(message)
                    if maya.parse(message.get(
                            "createdDateTime")) > last_time_we_checked:
                        self.logger.info("Analyzing message...")
                        if message_content:
                            self.logger.info("Checking message content.")
                            if compiled_message_content.search(
                                    message.get("body", {}).get("content",
                                                                "")):
                                self.logger.info("Returning new message.")
                                self.send({Output.MESSAGE: message})
                            else:
                                self.logger.info(
                                    f"Message did not match {message_content}")
                        else:
                            self.logger.info("Returning new message.")
                            self.send({Output.MESSAGE: message})
                    else:
                        # This speeds up execution a ton. The Beta endpoint doesn't limit how many messages are returned.
                        # Thus, get out of the loop as soon as we see an old message
                        self.logger.info("End of new messages")
                        break

                last_time_we_checked = temp_time
            else:
                self.logger.info("No new messages found...\n\n")
            time.sleep(params.get("interval", 10))