From e9a8526d1a21821823abbe1334818bd4bd9a318f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Harper?= Date: Mon, 14 Aug 2023 17:23:16 -0400 Subject: [PATCH] title case the first name --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fdf0a47..8b18732 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,17 @@ const engagementUserToken = process.env.YOUR_USER_TOKEN; const welcomeMessagePart1 = process.env.WELCOME_PART1; const welcomeMessagePart2 = process.env.WELCOME_PART2; +function titleCase(str) { + str = str.toLowerCase(); + str = str.split(' '); + + for (var i = 0; i < str.length; i++) { + str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1); + } + + return str.join(' '); +} + (async () => { // Start the app await app.start(process.env.PORT || 3000); @@ -94,7 +105,7 @@ const welcomeMessagePart2 = process.env.WELCOME_PART2; token: engagementUserToken, channel: imChannelId, link_names: true, - text: welcomeMessagePart1 + newUser[1].split(' ')[0] + welcomeMessagePart2, + text: welcomeMessagePart1 + titleCase(newUser[1].split(' ')[0]) + welcomeMessagePart2, as_user: 'yes' });