snowflakedb / SnowAlert

Security Analytics Using The Snowflake Data Warehouse
Apache License 2.0
184 stars 57 forks source link

Slack Group Message #544

Closed sfc-gh-rmahajan closed 3 years ago

sfc-gh-rmahajan commented 3 years ago

Slack Group Messages

case 1: When single recipient_email is passed i.e direct message:

Screenshot 2021-06-25 at 1 02 41 PM

Output:

Screenshot 2021-06-25 at 1 11 59 PM

Explaination: Here, for Single Email, string will be be passed as recipient so, convert it into list.

if isinstance(recipient_email, str): recipient_email = [recipient_email]

case 2: When more than one recipient_email is passed i.e group slack creation:

Screenshot 2021-06-25 at 1 08 42 PM

Output:

Screenshot 2021-06-25 at 1 09 09 PM

Explaination: If we get a list of emails, we need to iterate and get userId for each email and store it in as a list and then send all the ids as string by calling an API.

  for email in recipient_email:
      response = sc.api_call("users.lookupByEmail", email=email)
      if not response['ok']:
          log.error(f'Cannot identify Slack user for email {email}')
          continue
      users.append(response['user']['id'])
  user_ids = ",".join(users)                  
  result = sc.api_call("conversations.open", users=user_ids)