Skip to content

Commit

Permalink
Fix send_email_to_teams_user
Browse files Browse the repository at this point in the history
  • Loading branch information
karanpopat committed Dec 7, 2023
1 parent a7b6b91 commit 4756c5d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
team_id="Team_ID"

This file was deleted.

11 changes: 5 additions & 6 deletions send_message_to_user_in_microsoft_teams/mod.fp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
mod "send_message_to_user_in_microsoft_teams" {
title = "Send mail to user"
description = "Send a message to specific Teams user."
title = "Send Message to Teams User"
description = "Send an email to user in Microsoft Teams."

require {
mod "github.com/turbot/flowpipe-mod-teams" {
version = "v0.0.1-rc.12"
version = "v0.0.1-rc.13"
args = {
access_token = var.access_token
team_id = var.team_id
team_id = var.team_id
}
}
}
}
}
116 changes: 0 additions & 116 deletions send_message_to_user_in_microsoft_teams/send_email_to_user_in_teams.fp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
pipeline "send_email_to_teams_user" {
title = "Send Email Message to Specific Teams User"
description = "Send an email to specific Team user and communicate to Team with a an update messge."

param "to_email" {
type = string
description = "The email-id of the primary receipient."
}

param "subject" {
type = string
description = "The subject of the email."
}

param "content" {
type = string
description = "The content of the email."
}

param "team_id" {
type = string
description = "The unique identifier of the team."
default = var.team_id
}

param "channel_id" {
type = string
description = "The channel's unique identifier."
optional = true
}

# Check if the user exists in Teams by to_email
step "pipeline" "get_user_by_email" {
pipeline = teams.pipeline.get_user_by_email

args = {
user_email = param.to_email
}

# Exit pipeline, when the requested user is unavailable.
throw {
if = result.output.status_code == 404
message = "#### The requested user email is not found. Exiting the pipeline ####."
}
}

# Get all members of the team
step "pipeline" "list_team_members" {
depends_on = [step.pipeline.get_user_by_email]

pipeline = teams.pipeline.list_team_members

args = {
team_id = param.team_id
}
}

# Send email is the user is a member of the team
step "pipeline" "send_mail" {
depends_on = [step.pipeline.list_team_members]
for_each = { for user in step.pipeline.list_team_members.output.members : user.userId => user }
if = step.pipeline.get_user_by_email.output.user.id == each.key

pipeline = teams.pipeline.send_mail

args = {
to_email = ["${step.pipeline.get_user_by_email.output.user.userPrincipalName}"]
subject = param.subject
content = param.content
}
}

# Update specific team > channel with a message that mail is communicated
step "pipeline" "send_channel_message" {
depends_on = [step.pipeline.send_mail]
if = param.channel_id != null

pipeline = teams.pipeline.send_channel_message

args = {
team_id = param.team_id
channel_id = param.channel_id
message = "Mail sent to ${step.pipeline.get_user_by_email.output.user.displayName}(${step.pipeline.get_user_by_email.output.user.userPrincipalName})."
}
}
}
5 changes: 0 additions & 5 deletions send_message_to_user_in_microsoft_teams/variables.fp
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
variable "access_token" {
description = "The Microsoft personal security access_token to authenticate to the Microsoft graph APIs."
type = string
}

variable "team_id" {
description = "The unique identifier of the Team."
type = string
Expand Down

0 comments on commit 4756c5d

Please sign in to comment.