67 lines
2.0 KiB
Bash
67 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
# Variables
|
|
ROCKET_CHAT_URL="https:///chat.koozali.org" # Replace with your Rocket.Chat URL
|
|
TOKEN="LwSxku5012GVjT5GKukvCiAE3jmxzNREsJ3ZO87oP1D" # Replace with your user token
|
|
DISCUSSION_ID="X2Wk3W5taM9PJYP4R" # Replace with the discussion ID
|
|
CHANNEL_ID="66d16fbceffca216c2ca2f4e" # Replace with the channel ID
|
|
USER_ID="9RmjfwmQZc9pYrC9G"
|
|
|
|
# Function to get members from the discussion
|
|
get_discussion_members() {
|
|
curl -s -X GET "$ROCKET_CHAT_URL/api/v1/channels.members?roomId=$DISCUSSION_ID" \
|
|
-H "X-Auth-Token: $TOKEN" \
|
|
-H "X-User-Id: $USER_ID" \
|
|
-H "Content-Type: application/json"
|
|
}
|
|
|
|
# Function to add a member to the channel
|
|
add_member_to_channel() {
|
|
local member_id=$1
|
|
curl -s -X POST "$ROCKET_CHAT_URL/api/v1/channels.invite" \
|
|
-H "X-Auth-Token: $TOKEN" \
|
|
-H "X-User-Id: $USER_ID" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"roomId\":\"$CHANNEL_ID\", \"userId\":\"$member_id\"}"
|
|
}
|
|
|
|
get_channel_list() {
|
|
curl -s -X GET "$ROCKET_CHAT_URL/api/v1/channels.list" \
|
|
-H "X-Auth-Token: $TOKEN" \
|
|
-H "X-User-Id: $USER_ID" \
|
|
-H "Content-Type: application/json"
|
|
}
|
|
|
|
# Main Logic
|
|
channels=$(get_channel_list)
|
|
echo $channels
|
|
#exit 0
|
|
#channel_names=$(echo "$channels" | jq -r '.channels[]._id')
|
|
channel_names=$(echo "$channels" | jq -r '.channels[] | "\(._id) \(.fname)"' | tr ' ' '\n' | grep SME11)
|
|
for name in $channel_names; do
|
|
echo $name
|
|
done
|
|
|
|
|
|
#exit 0
|
|
|
|
# Fetch the members
|
|
members_response=$(get_discussion_members)
|
|
echo $members_response
|
|
exit 0
|
|
|
|
# Parse the user IDs from the response (you might need to modify this according to the API response structure)
|
|
member_ids=$(echo "$members_response" | jq -r '.members[]._id')
|
|
echo $member_ids
|
|
|
|
# Iterate over each member and add them to the specified channel
|
|
i=0
|
|
for member_id in $member_ids; do
|
|
echo $member_id
|
|
add_member_to_channel "$member_id"
|
|
echo "Added member $member_id to channel"
|
|
#exit 1
|
|
((i++))
|
|
done
|
|
|
|
echo "$i members added to the channel." |