Skip to content

Commit 1f516a6

Browse files
Making group DMs on pairing
1 parent 16256f5 commit 1f516a6

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

src/coffeeChats/controllers.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,28 +178,34 @@ const createPairings = (
178178
};
179179

180180
/**
181-
* Sends DMs to paired users
181+
* Creates a group DM and notifies paired users
182182
*/
183183
const notifyPairing = async (userIds: string[]): Promise<void> => {
184184
const userMentions = userIds.map((id) => `<@${id}>`).join(", ");
185185
const activity = getRandomActivity();
186186

187-
for (const userId of userIds) {
188-
try {
189-
const result = await slackbot.client.chat.postMessage({
190-
channel: userId,
191-
text: `Hey! You've been paired for a coffee chat with ${userMentions.replace(
192-
`<@${userId}>`,
193-
"your partner(s)",
194-
)}. ☕\n\nSuggested activity: *${activity}*\n\nTake some time in the next two weeks to connect and get to know each other better!`,
195-
});
187+
try {
188+
// Create a group DM with all users in the pairing
189+
const conversation = await slackbot.client.conversations.open({
190+
users: userIds.join(","),
191+
});
196192

197-
if (!result.ok) {
198-
logWithTime(`Failed to send DM to user ${userId}`);
199-
}
200-
} catch (error) {
201-
logWithTime(`Error sending DM to user ${userId}: ${error}`);
193+
if (!conversation.ok || !conversation.channel) {
194+
logWithTime(`Failed to create group DM for users: ${userIds.join(", ")}`);
195+
return;
202196
}
197+
198+
// Send a message to the group DM
199+
const messageResult = await slackbot.client.chat.postMessage({
200+
channel: conversation.channel.id!,
201+
text: `Hey ${userMentions}! You've been paired for a coffee chat. ☕\n\nSuggested activity: *${activity}*\n\nTake some time in the next two weeks to connect and get to know each other better!`,
202+
});
203+
204+
if (!messageResult.ok) {
205+
logWithTime(`Failed to send message to group DM: ${conversation.channel.id}`);
206+
}
207+
} catch (error) {
208+
logWithTime(`Error creating group DM for users ${userIds.join(", ")}: ${error}`);
203209
}
204210
};
205211

0 commit comments

Comments
 (0)