def run(self, params={}): group_id = get_group_id_from_name(self.logger, self.connection, params.get(Input.GROUP_NAME)) channels = get_channels_from_microsoft(self.logger, self.connection, group_id, params.get(Input.CHANNEL_NAME)) user_id = get_user_info(self.logger, self.connection, params.get(Input.MEMBER_LOGIN)) try: channel_id = channels[0].get("id") user_id = user_id.get("id") if not channel_id: raise PluginException( cause="The specified channel does not exist.", assistance="Please check that channel name is correct." ) if not user_id: raise PluginException( cause="The specified user does not exist.", assistance="Please check that member login is correct." ) except IndexError as e: raise PluginException( cause="The specified channel does not exist.", assistance="If the issue persists please contact support.", data=e ) return { Output.SUCCESS: add_user_to_channel( self.logger, self.connection, group_id, channel_id, user_id ) }
def test_integration_delete_channel(self): log = logging.getLogger("Test") test_connection = Connection() test_connection.logger = log with open("../tests/send_message.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") test_connection.connect(connection_params) channels = get_channels_from_microsoft(log, test_connection, TEAM_ID, TEST_CHANNEL_NAME, True) channel_id = channels[0].get("id") result = delete_channel(log, test_connection, TEAM_ID, channel_id) # Leaving this code here - This can be used for bulk delete if needed # for i in range(100): # channel_name = f"{i}_test_channel_3" # channels = get_channels_from_microsoft(log, test_connection, TEAM_ID, channel_name) # channel_id = channels[0].get("id") # delete_channel(log, test_connection, TEAM_ID, channel_id) # time.sleep(1) self.assertTrue(result)
def run(self, params={}): team_name = params.get(Input.TEAM_NAME) channel_name = params.get(Input.CHANNEL_NAME) 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") success = delete_channel(self.logger, self.connection, team_id, channel_id) return {Output.SUCCESS: success}
def setup_endpoint(self, channel_name: str, team_name: str) -> str: """ This takes a team name and channel in that team and generates a get messages endpoint. :param channel_name: String :param team_name: String :return: String (URL) """ team = get_teams_from_microsoft(self.logger, self.connection, team_name) team_id = team[0].get("id") channel = get_channels_from_microsoft(self.logger, self.connection, team_id, channel_name) channel_id = channel[0].get("id") messages_endpoint = f"https://graph.microsoft.com/beta/teams/{team_id}/channels/{channel_id}/messages" return messages_endpoint
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}
def test_delete_channel(self): log = logging.getLogger("Test") test_connection = Connection() test_connection.logger = log with open("../tests/send_message.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") test_connection.connect(connection_params) channels = get_channels_from_microsoft(log, test_connection, TEAM_ID, TEST_CHANNEL_NAME) channel_id = channels[0].get("id") result = delete_channel(log, test_connection, TEAM_ID, channel_id) self.assertTrue(result)
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}
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)}