-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Remove Members from Channel closes #29
- Loading branch information
1 parent
e1a5b28
commit 72b60f2
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
pipeline "kick_users_from_channel" { | ||
title = "Remove Users from Channel" | ||
description = "Removes users from a Slack channel." | ||
|
||
param "conn" { | ||
type = connection.slack | ||
description = local.conn_param_description | ||
default = connection.slack.default | ||
} | ||
|
||
param "channel" { | ||
type = string | ||
description = "The ID of the public or private channel to remove user(s) from." | ||
} | ||
|
||
param "users" { | ||
type = list(string) | ||
description = "A list of user IDs to remove from the channel." | ||
} | ||
|
||
step "http" "remove_user_from_channel" { | ||
for_each = param.users | ||
|
||
method = "post" | ||
url = "https://slack.com/api/conversations.kick" | ||
|
||
request_headers = { | ||
Content-Type = "application/json; charset=utf-8" | ||
Authorization = "Bearer ${param.conn.token}" | ||
} | ||
|
||
request_body = jsonencode({ | ||
channel = param.channel | ||
user = each.value | ||
}) | ||
|
||
throw { | ||
if = result.response_body.ok == false | ||
message = result.response_body.error | ||
} | ||
} | ||
|
||
output "kicked_users" { | ||
description = "List of users successfully removed from the channel." | ||
value = [for user in param.users: user if step.http.remove_user_from_channel[user].response_body.ok == true] | ||
} | ||
} |