From 9a9b756002fa7bbea92711e155e59b83b7661b94 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 12:20:25 +0530 Subject: [PATCH 01/42] Added logs for debugging --- middlewares/assignRawBody.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/middlewares/assignRawBody.js b/middlewares/assignRawBody.js index 43b3158..f0038cd 100644 --- a/middlewares/assignRawBody.js +++ b/middlewares/assignRawBody.js @@ -13,7 +13,8 @@ class AssignRawBody { */ assignRawBody(requestBody) { const oThis = this; - const requestRawBody = qs.stringify(requestBody).replace(/%20/g, '+'); + console.log('Not replacing %20 with +'); + // const requestRawBody = qs.stringify(requestBody).replace(/%20/g, '+'); return requestRawBody; } } From b37584817b76c810888397d941ca3a5371ceeb64 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 12:31:57 +0530 Subject: [PATCH 02/42] Bug fix --- middlewares/assignRawBody.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middlewares/assignRawBody.js b/middlewares/assignRawBody.js index f0038cd..72ca37a 100644 --- a/middlewares/assignRawBody.js +++ b/middlewares/assignRawBody.js @@ -15,7 +15,7 @@ class AssignRawBody { const oThis = this; console.log('Not replacing %20 with +'); // const requestRawBody = qs.stringify(requestBody).replace(/%20/g, '+'); - return requestRawBody; + return requestBody; } } From 6d2a2f0188263de7335fd0d917eb5f200aff4ea0 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 13:02:11 +0530 Subject: [PATCH 03/42] Json stringified --- middlewares/authentication/RawBodyParams.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middlewares/authentication/RawBodyParams.js b/middlewares/authentication/RawBodyParams.js index 15648d7..4704a4d 100644 --- a/middlewares/authentication/RawBodyParams.js +++ b/middlewares/authentication/RawBodyParams.js @@ -28,7 +28,7 @@ class ValidateRawBodyParams { const oThis = this; if (!CommonValidators.validateString(oThis.rawBody)) { - console.error(`Slack authentication failed. Invalid raw Body Input ${oThis.rawBody}`); + console.error(`Slack authentication failed. Invalid raw Body Input ${JSON.stringify(oThis.rawBody)}`); return responseHelper.error({ internal_error_identifier: 'm_a_rbp_p', api_error_identifier: 'unauthorized_api_request', From 33cf0019ed6088792c914720e07f4316937e361c Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 13:46:08 +0530 Subject: [PATCH 04/42] Added logs for debugging --- middlewares/assignRawBody.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/middlewares/assignRawBody.js b/middlewares/assignRawBody.js index 72ca37a..05447ed 100644 --- a/middlewares/assignRawBody.js +++ b/middlewares/assignRawBody.js @@ -13,9 +13,12 @@ class AssignRawBody { */ assignRawBody(requestBody) { const oThis = this; - console.log('Not replacing %20 with +'); - // const requestRawBody = qs.stringify(requestBody).replace(/%20/g, '+'); - return requestBody; + console.log('before replacing + requestRawBody: ----->', requestBody); + + const requestRawBody = qs.stringify(requestBody).replace(/%20/g, '+'); + + console.log('after replacing + requestRawBody: ----->', requestRawBody); + return requestRawBody; } } From fddbafb1671179328ab609e8e6faf37d750d3990 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 18:35:23 +0530 Subject: [PATCH 05/42] Fixed common middlewares signature validation --- lib/middlewareMethods/Common.js | 31 ++++++++++++++++----- middlewares/authentication/Authenticator.js | 16 +++-------- middlewares/authentication/Signature.js | 23 +++++++-------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/lib/middlewareMethods/Common.js b/lib/middlewareMethods/Common.js index cb11c92..6ce3710 100644 --- a/lib/middlewareMethods/Common.js +++ b/lib/middlewareMethods/Common.js @@ -16,30 +16,47 @@ class CommonMiddlewares { * @param requestMethod * @returns {{requestQuery: *, internalDecodedParams: {}, decodedParams: (*|{}), requestBody: *}} */ - async CommonMiddleWareMethod(requestBody, requestQuery, requestHeaders, requestMethod) { + async CommonMiddleWareMethod(req) { let internalDecodedParams = {}, decodedParams = {}; - const requestRawBody = AssignRawBodyMiddleware.assignRawBody(requestBody); + let requestBody = req.body, + requestRawBody = req.rawBody, + requestQuery = req.query, + requestHeaders = req.headers, + requestMethod = req.method; + // 1. Validate slack signature + await authenticator.validateSlackSignature(req); + + // 2. Payload formatting const formattedPayload = PayloadFormatterMiddleware.formatPayload(requestBody); requestBody.payload = formattedPayload; - const sanitisedResponse = sanitizer.sanitizeBodyAndQuery(requestBody, requestQuery); - requestBody = sanitisedResponse.requestBody; - requestQuery = sanitisedResponse.requestQuery; + // 3. Sanitize body and query + const sanitizedResponse = sanitizer.sanitizeBodyAndQuery(requestBody, requestQuery); + requestBody = sanitizedResponse.requestBody; + requestQuery = sanitizedResponse.requestQuery; + // 4. Assign request params decodedParams = AssignParamsMiddleware.assignParams(requestMethod, requestBody, requestQuery); + // 5. Extract slack params const slackParamsResponse = ExtractSlackParamsMiddleware.extractSlackParams(requestBody, internalDecodedParams); requestBody = slackParamsResponse.requestBody; internalDecodedParams = slackParamsResponse.internalDecodedParams; + // 6. Validate raw body params await authenticator.validateRawBodyParams(requestRawBody); + + // 7. Validate request headers await authenticator.validateRequestHeaders(requestHeaders); + + // 8. Validate request domain await authenticator.validateRequestDomain(requestBody); - await authenticator.validateSlackSignature(requestRawBody, requestHeaders, requestBody); - await authenticator.validateSlackUser(requestRawBody, requestHeaders, requestBody); + + // 9. Validate slack user + await authenticator.validateSlackUser(requestBody); return { decodedParams, internalDecodedParams, requestBody, requestQuery }; } diff --git a/middlewares/authentication/Authenticator.js b/middlewares/authentication/Authenticator.js index efeacc2..5130034 100644 --- a/middlewares/authentication/Authenticator.js +++ b/middlewares/authentication/Authenticator.js @@ -55,17 +55,11 @@ class Authenticator { /** * Function to validate slack signature. * - * @param {object} requestRawBody - * @param {object} requestHeaders - * @param {object} requestBody + * @param {object} req * @returns {Promise} */ - async validateSlackSignature(requestRawBody, requestHeaders, requestBody) { - const authResponse = await new ValidateSlackSignature({ - rawBody: requestRawBody, - requestHeaders: requestHeaders, - slackRequestParams: requestBody - }).perform(); + async validateSlackSignature(req) { + const authResponse = await new ValidateSlackSignature(req).perform(); if (authResponse.isFailure()) { throw new Error('Invalid Slack Signature'); @@ -80,10 +74,8 @@ class Authenticator { * @param {object} requestBody * @returns {Promise} */ - async validateSlackUser(requestRawBody, requestHeaders, requestBody) { + async validateSlackUser(requestBody) { const authResponse = await new ValidateSlackUser({ - rawBody: requestRawBody, - requestHeaders: requestHeaders, slackRequestParams: requestBody }).perform(); diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index fdf4ae8..61fb78a 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -19,11 +19,10 @@ class ValidateSlackSignature { constructor(params) { const oThis = this; - oThis.rawBody = params.rawBody; - oThis.requestHeaders = params.requestHeaders; - oThis.slackRequestParams = params.slackRequestParams; - - oThis.requestPayload = oThis.slackRequestParams.payload || null; + oThis.req = params.req; + oThis.reqHeaders = req.headers; + oThis.apiAppId = req.body.api_app_id; + oThis.reqRawBody = req.rawBody; } /** @@ -38,9 +37,9 @@ class ValidateSlackSignature { try { const oThis = this; - const requestTimestamp = oThis.requestHeaders['x-slack-request-timestamp']; + const requestTimestamp = oThis.reqHeaders['x-slack-request-timestamp']; - const requestHeaderSignature = oThis.requestHeaders['x-slack-signature']; + const requestHeaderSignature = oThis.reqHeaders['x-slack-signature']; const splitRequestHeaderSignature = requestHeaderSignature.split('='), version = splitRequestHeaderSignature[0], signature = splitRequestHeaderSignature[1]; @@ -61,9 +60,8 @@ class ValidateSlackSignature { internal_error_identifier: 'm_a_s_p', api_error_identifier: 'unauthorized_api_request', debug_options: { - body: oThis.rawBody, - headers: oThis.requestHeaders, - slackRequestParams: oThis.slackRequestParams + rawBody: oThis.reqRawBody, + headers: oThis.reqHeaders, } }); } @@ -88,10 +86,9 @@ class ValidateSlackSignature { async _validateSignature(requestTimestamp, version, signature) { const oThis = this; - const appId = oThis.slackRequestParams.api_app_id; - const signingSecret = slackAppConstants.getSigningSecretForAppId(appId); + const signingSecret = slackAppConstants.getSigningSecretForAppId(oThis.apiAppId); - const signatureString = `${version}:${requestTimestamp}:${oThis.rawBody}`; + const signatureString = `${version}:${requestTimestamp}:${oThis.reqRawBody}`; const computedSignature = crypto .createHmac('sha256', signingSecret) .update(signatureString) From 2bd909db209f733e1fe25397adc7e3a379a37b13 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 18:43:27 +0530 Subject: [PATCH 06/42] FIxed req param --- middlewares/authentication/Authenticator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middlewares/authentication/Authenticator.js b/middlewares/authentication/Authenticator.js index 5130034..7eb4ed0 100644 --- a/middlewares/authentication/Authenticator.js +++ b/middlewares/authentication/Authenticator.js @@ -59,7 +59,7 @@ class Authenticator { * @returns {Promise} */ async validateSlackSignature(req) { - const authResponse = await new ValidateSlackSignature(req).perform(); + const authResponse = await new ValidateSlackSignature({ req: req }).perform(); if (authResponse.isFailure()) { throw new Error('Invalid Slack Signature'); From 42b4e2f4205d69296ac9dc26d65c26aa199238ad Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 18:54:28 +0530 Subject: [PATCH 07/42] Param fixes --- index.js | 8 +++++++- lib/middlewareMethods/Common.js | 14 +++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 3c6dfb6..862c182 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,13 @@ class SlackAdmin { return async function(req, res, next) { try { - const response = await oThis.validators.common(req.body, req.query, req.headers, req.method); + const response = await oThis.validators.common( + req.body, + req.rawBody, + req.query, + req.headers, + req.method + ); req.body = response.requestBody; req.query = response.requestQuery; diff --git a/lib/middlewareMethods/Common.js b/lib/middlewareMethods/Common.js index 6ce3710..d2a0d01 100644 --- a/lib/middlewareMethods/Common.js +++ b/lib/middlewareMethods/Common.js @@ -16,16 +16,16 @@ class CommonMiddlewares { * @param requestMethod * @returns {{requestQuery: *, internalDecodedParams: {}, decodedParams: (*|{}), requestBody: *}} */ - async CommonMiddleWareMethod(req) { + async CommonMiddleWareMethod( + requestBody, + requestRawBody, + requestQuery, + requestHeaders, + requestMethod + ) { let internalDecodedParams = {}, decodedParams = {}; - let requestBody = req.body, - requestRawBody = req.rawBody, - requestQuery = req.query, - requestHeaders = req.headers, - requestMethod = req.method; - // 1. Validate slack signature await authenticator.validateSlackSignature(req); From dccbac77913eca541e052ec519d6fe11760444a5 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 19:10:08 +0530 Subject: [PATCH 08/42] Param fixes --- lib/middlewareMethods/Common.js | 2 +- middlewares/authentication/Authenticator.js | 8 ++++++-- middlewares/authentication/Signature.js | 19 ++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/middlewareMethods/Common.js b/lib/middlewareMethods/Common.js index d2a0d01..e5d8c01 100644 --- a/lib/middlewareMethods/Common.js +++ b/lib/middlewareMethods/Common.js @@ -27,7 +27,7 @@ class CommonMiddlewares { decodedParams = {}; // 1. Validate slack signature - await authenticator.validateSlackSignature(req); + await authenticator.validateSlackSignature(requestBody, requestRawBody, requestHeaders); // 2. Payload formatting const formattedPayload = PayloadFormatterMiddleware.formatPayload(requestBody); diff --git a/middlewares/authentication/Authenticator.js b/middlewares/authentication/Authenticator.js index 7eb4ed0..94bd517 100644 --- a/middlewares/authentication/Authenticator.js +++ b/middlewares/authentication/Authenticator.js @@ -58,8 +58,12 @@ class Authenticator { * @param {object} req * @returns {Promise} */ - async validateSlackSignature(req) { - const authResponse = await new ValidateSlackSignature({ req: req }).perform(); + async validateSlackSignature(requestBody, requestRawBody, requestHeaders) { + const authResponse = await new ValidateSlackSignature({ + requestBody: requestBody, + requestRawBody: requestRawBody, + requestHeaders: requestHeaders + }).perform(); if (authResponse.isFailure()) { throw new Error('Invalid Slack Signature'); diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 61fb78a..215436b 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -19,10 +19,11 @@ class ValidateSlackSignature { constructor(params) { const oThis = this; - oThis.req = params.req; - oThis.reqHeaders = req.headers; - oThis.apiAppId = req.body.api_app_id; - oThis.reqRawBody = req.rawBody; + const requestBody = params.requestBody; + oThis.requestRawBody = params.requestRawBody; + oThis.requestHeaders = params.requestHeaders; + + oThis.apiAppId = requestBody.api_app_id; } /** @@ -37,9 +38,9 @@ class ValidateSlackSignature { try { const oThis = this; - const requestTimestamp = oThis.reqHeaders['x-slack-request-timestamp']; + const requestTimestamp = oThis.requestHeaders['x-slack-request-timestamp']; - const requestHeaderSignature = oThis.reqHeaders['x-slack-signature']; + const requestHeaderSignature = oThis.requestHeaders['x-slack-signature']; const splitRequestHeaderSignature = requestHeaderSignature.split('='), version = splitRequestHeaderSignature[0], signature = splitRequestHeaderSignature[1]; @@ -60,8 +61,8 @@ class ValidateSlackSignature { internal_error_identifier: 'm_a_s_p', api_error_identifier: 'unauthorized_api_request', debug_options: { - rawBody: oThis.reqRawBody, - headers: oThis.reqHeaders, + rawBody: oThis.requestRawBody, + headers: oThis.requestHeaders, } }); } @@ -88,7 +89,7 @@ class ValidateSlackSignature { const signingSecret = slackAppConstants.getSigningSecretForAppId(oThis.apiAppId); - const signatureString = `${version}:${requestTimestamp}:${oThis.reqRawBody}`; + const signatureString = `${version}:${requestTimestamp}:${oThis.requestRawBody}`; const computedSignature = crypto .createHmac('sha256', signingSecret) .update(signatureString) From 9a185bda6e8563dd14901f8516d2561f37a6639b Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 19:29:46 +0530 Subject: [PATCH 09/42] Added logs for debugging --- middlewares/authentication/Signature.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 215436b..6117377 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -87,6 +87,7 @@ class ValidateSlackSignature { async _validateSignature(requestTimestamp, version, signature) { const oThis = this; + console.log('oThis.requestRawBody: ------- ', oThis.requestRawBody); const signingSecret = slackAppConstants.getSigningSecretForAppId(oThis.apiAppId); const signatureString = `${version}:${requestTimestamp}:${oThis.requestRawBody}`; @@ -94,6 +95,9 @@ class ValidateSlackSignature { .createHmac('sha256', signingSecret) .update(signatureString) .digest('hex'); + + console.log('computedSignature: ------- ', computedSignature); + console.log('signatureString: ------- ', signatureString); if (!crypto.timingSafeEqual(Buffer.from(signature, 'utf-8'), Buffer.from(computedSignature, 'utf-8'))) { console.error(`Invalid signature :: ${signature}`); From 70ac774fb823cc1c1d9cfbf16a8b47b4f5537002 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 19:37:47 +0530 Subject: [PATCH 10/42] Added logs for debugging --- middlewares/authentication/Signature.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 6117377..bc34c65 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -96,8 +96,9 @@ class ValidateSlackSignature { .update(signatureString) .digest('hex'); - console.log('computedSignature: ------- ', computedSignature); console.log('signatureString: ------- ', signatureString); + console.log('computedSignature: ------- ', computedSignature); + console.log('signature: ------- ', signature); if (!crypto.timingSafeEqual(Buffer.from(signature, 'utf-8'), Buffer.from(computedSignature, 'utf-8'))) { console.error(`Invalid signature :: ${signature}`); From 1e8fa3cb7816f9886e30d9cc4a40aaad5f5bed81 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 20:03:50 +0530 Subject: [PATCH 11/42] Added encoding to sig validation --- middlewares/authentication/Signature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index bc34c65..2fe5cff 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -93,7 +93,7 @@ class ValidateSlackSignature { const signatureString = `${version}:${requestTimestamp}:${oThis.requestRawBody}`; const computedSignature = crypto .createHmac('sha256', signingSecret) - .update(signatureString) + .update(signatureString, 'utf-8') .digest('hex'); console.log('signatureString: ------- ', signatureString); From b4c7433b8e4eec4a4dd8f0612ba0bf7af2bb18c5 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 20:11:35 +0530 Subject: [PATCH 12/42] Added logs for debugging --- middlewares/authentication/Signature.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 2fe5cff..0499391 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -90,11 +90,13 @@ class ValidateSlackSignature { console.log('oThis.requestRawBody: ------- ', oThis.requestRawBody); const signingSecret = slackAppConstants.getSigningSecretForAppId(oThis.apiAppId); + console.log('signingSecret: ------- ', signingSecret); + const signatureString = `${version}:${requestTimestamp}:${oThis.requestRawBody}`; const computedSignature = crypto - .createHmac('sha256', signingSecret) - .update(signatureString, 'utf-8') - .digest('hex'); + .createHmac('sha256', signingSecret) + .update(signatureString, 'utf8') + .digest('hex'); console.log('signatureString: ------- ', signatureString); console.log('computedSignature: ------- ', computedSignature); From f0fb4fe0e2b92f7c9872d4fa39b1e71e3acf0f8f Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 20:18:21 +0530 Subject: [PATCH 13/42] Api app id fix --- middlewares/authentication/Signature.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 0499391..783361d 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -23,7 +23,8 @@ class ValidateSlackSignature { oThis.requestRawBody = params.requestRawBody; oThis.requestHeaders = params.requestHeaders; - oThis.apiAppId = requestBody.api_app_id; + console.log('requestBody.payload: ------- ', requestBody.payload); + oThis.apiAppId = requestBody.payload.api_app_id; } /** From 496042666f78c3c545b909bd5c2b670e01d645e4 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Tue, 13 Feb 2024 20:25:38 +0530 Subject: [PATCH 14/42] Added logs for debugging --- middlewares/authentication/Signature.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 783361d..d7e61f8 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -25,6 +25,8 @@ class ValidateSlackSignature { console.log('requestBody.payload: ------- ', requestBody.payload); oThis.apiAppId = requestBody.payload.api_app_id; + + console.log('oThis.apiAppId: ------- ', oThis.apiAppId); } /** From 9eef333b41ba8fe1ac11a7fedc5c2a50585089c5 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 11:12:22 +0530 Subject: [PATCH 15/42] Added logs for debugging --- index.js | 8 ++++---- middlewares/authentication/Signature.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 862c182..696a7df 100644 --- a/index.js +++ b/index.js @@ -52,10 +52,10 @@ class SlackAdmin { return async function(req, res, next) { try { const response = await oThis.validators.common( - req.body, + req.body, req.rawBody, - req.query, - req.headers, + req.query, + req.headers, req.method ); @@ -65,7 +65,7 @@ class SlackAdmin { req.decodedParams = response.decodedParams; next(); } catch (errorMessage) { - console.error('Common middleaware error:', errorMessage); + console.error('Common middleware error:', errorMessage); return res.status(200).json('Something went wrong.'); } }; diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index d7e61f8..b2c227b 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -19,7 +19,8 @@ class ValidateSlackSignature { constructor(params) { const oThis = this; - const requestBody = params.requestBody; + console.log('type of params.requestBody: ------- ', typeof params.requestBody); + const requestBody = JSON.parse(params.requestBody); // Parse the request body to get the payload oThis.requestRawBody = params.requestRawBody; oThis.requestHeaders = params.requestHeaders; From 898b8285cd8eb07a086d03f6942827ead18a9bab Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 11:22:10 +0530 Subject: [PATCH 16/42] Fix --- middlewares/authentication/Signature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index b2c227b..eaddf3b 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -20,7 +20,7 @@ class ValidateSlackSignature { const oThis = this; console.log('type of params.requestBody: ------- ', typeof params.requestBody); - const requestBody = JSON.parse(params.requestBody); // Parse the request body to get the payload + const requestBody = params.requestBody oThis.requestRawBody = params.requestRawBody; oThis.requestHeaders = params.requestHeaders; From d249c3d1666f5dc52a86d857b61dd151b9a27252 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 11:27:11 +0530 Subject: [PATCH 17/42] Fix --- middlewares/authentication/Signature.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index eaddf3b..faa5441 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -25,7 +25,11 @@ class ValidateSlackSignature { oThis.requestHeaders = params.requestHeaders; console.log('requestBody.payload: ------- ', requestBody.payload); - oThis.apiAppId = requestBody.payload.api_app_id; + if (requestBody.payload) { + oThis.apiAppId = requestBody.payload.api_app_id; + } else { + oThis.apiAppId = requestBody.api_app_id; + } console.log('oThis.apiAppId: ------- ', oThis.apiAppId); } From c4d9520d56cc55def2a9311c4d57d44671b94949 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 11:38:39 +0530 Subject: [PATCH 18/42] Added logs for debugging --- middlewares/authentication/RawBodyParams.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/middlewares/authentication/RawBodyParams.js b/middlewares/authentication/RawBodyParams.js index 4704a4d..82fac96 100644 --- a/middlewares/authentication/RawBodyParams.js +++ b/middlewares/authentication/RawBodyParams.js @@ -16,6 +16,8 @@ class ValidateRawBodyParams { constructor(params) { const oThis = this; + console.log('type of params.rawBody: ------- ', typeof params.rawBody); + console.log('params: ------- ', params); oThis.rawBody = params.rawBody; } From 00a5d9131cee98348e697c59cebe53f6ac425993 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 12:02:53 +0530 Subject: [PATCH 19/42] Added logs for debugging --- middlewares/authentication/Signature.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index faa5441..2fd58e6 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -26,6 +26,10 @@ class ValidateSlackSignature { console.log('requestBody.payload: ------- ', requestBody.payload); if (requestBody.payload) { + console.log('requestBody.payload.api_app_id: ------- ', requestBody.payload.api_app_id); + console.log('requestBody.payload.type: ------- ', requestBody.payload.type); + console.log('requestBody.payload.user: ------- ', requestBody.payload.user); + console.log('requestBody.payload.token: ------- ', requestBody.payload.token); oThis.apiAppId = requestBody.payload.api_app_id; } else { oThis.apiAppId = requestBody.api_app_id; From 458de712c2ea015198b9968fadb0d9eab6758911 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 12:10:19 +0530 Subject: [PATCH 20/42] Added logs for debugging --- middlewares/authentication/Signature.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 2fd58e6..782b366 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -20,7 +20,9 @@ class ValidateSlackSignature { const oThis = this; console.log('type of params.requestBody: ------- ', typeof params.requestBody); - const requestBody = params.requestBody + + console.log('Payload keys: ------- ', Object.keys(params.requestBody.payload)); + const requestBody = params.requestBody; oThis.requestRawBody = params.requestRawBody; oThis.requestHeaders = params.requestHeaders; @@ -30,6 +32,7 @@ class ValidateSlackSignature { console.log('requestBody.payload.type: ------- ', requestBody.payload.type); console.log('requestBody.payload.user: ------- ', requestBody.payload.user); console.log('requestBody.payload.token: ------- ', requestBody.payload.token); + console.log('Payload keys in if: ------- ', Object.keys(requestBody.payload)); oThis.apiAppId = requestBody.payload.api_app_id; } else { oThis.apiAppId = requestBody.api_app_id; From 5c2b4debada99dce7aa73ccb4fd6c2aac3a23c64 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 12:18:29 +0530 Subject: [PATCH 21/42] Parsed payload --- middlewares/authentication/Signature.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 782b366..48883c9 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -28,12 +28,13 @@ class ValidateSlackSignature { console.log('requestBody.payload: ------- ', requestBody.payload); if (requestBody.payload) { - console.log('requestBody.payload.api_app_id: ------- ', requestBody.payload.api_app_id); - console.log('requestBody.payload.type: ------- ', requestBody.payload.type); - console.log('requestBody.payload.user: ------- ', requestBody.payload.user); - console.log('requestBody.payload.token: ------- ', requestBody.payload.token); - console.log('Payload keys in if: ------- ', Object.keys(requestBody.payload)); - oThis.apiAppId = requestBody.payload.api_app_id; + const parsedPayload = JSON.parse(requestBody.payload); + console.log('requestBody.payload.api_app_id: ------- ', parsedPayload.payload.api_app_id); + console.log('parsedPayload.payload.type: ------- ', parsedPayload.payload.type); + console.log('parsedPayload.payload.user: ------- ', parsedPayload.payload.user); + console.log('parsedPayload.payload.token: ------- ', parsedPayload.payload.token); + console.log('Payload keys in if: ------- ', Object.keys(parsedPayload.payload)); + oThis.apiAppId = parsedPayload.payload.api_app_id; } else { oThis.apiAppId = requestBody.api_app_id; } From 59f75cd385593e239f48892235cb4aea909e8e57 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 12:37:31 +0530 Subject: [PATCH 22/42] Parsed payload --- middlewares/assignRawBody.js | 2 -- middlewares/authentication/RawBodyParams.js | 2 -- middlewares/authentication/Signature.js | 9 ++------- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/middlewares/assignRawBody.js b/middlewares/assignRawBody.js index 05447ed..7283f91 100644 --- a/middlewares/assignRawBody.js +++ b/middlewares/assignRawBody.js @@ -13,11 +13,9 @@ class AssignRawBody { */ assignRawBody(requestBody) { const oThis = this; - console.log('before replacing + requestRawBody: ----->', requestBody); const requestRawBody = qs.stringify(requestBody).replace(/%20/g, '+'); - console.log('after replacing + requestRawBody: ----->', requestRawBody); return requestRawBody; } } diff --git a/middlewares/authentication/RawBodyParams.js b/middlewares/authentication/RawBodyParams.js index 82fac96..4704a4d 100644 --- a/middlewares/authentication/RawBodyParams.js +++ b/middlewares/authentication/RawBodyParams.js @@ -16,8 +16,6 @@ class ValidateRawBodyParams { constructor(params) { const oThis = this; - console.log('type of params.rawBody: ------- ', typeof params.rawBody); - console.log('params: ------- ', params); oThis.rawBody = params.rawBody; } diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 48883c9..1a2c71b 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -21,7 +21,6 @@ class ValidateSlackSignature { console.log('type of params.requestBody: ------- ', typeof params.requestBody); - console.log('Payload keys: ------- ', Object.keys(params.requestBody.payload)); const requestBody = params.requestBody; oThis.requestRawBody = params.requestRawBody; oThis.requestHeaders = params.requestHeaders; @@ -29,12 +28,8 @@ class ValidateSlackSignature { console.log('requestBody.payload: ------- ', requestBody.payload); if (requestBody.payload) { const parsedPayload = JSON.parse(requestBody.payload); - console.log('requestBody.payload.api_app_id: ------- ', parsedPayload.payload.api_app_id); - console.log('parsedPayload.payload.type: ------- ', parsedPayload.payload.type); - console.log('parsedPayload.payload.user: ------- ', parsedPayload.payload.user); - console.log('parsedPayload.payload.token: ------- ', parsedPayload.payload.token); - console.log('Payload keys in if: ------- ', Object.keys(parsedPayload.payload)); - oThis.apiAppId = parsedPayload.payload.api_app_id; + console.log('parsedPayload.api_app_id: ------- ', parsedPayload.api_app_id); + oThis.apiAppId = parsedPayload.api_app_id; } else { oThis.apiAppId = requestBody.api_app_id; } From 9362203216a50888d03171ad2e20807d86a20502 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 12:52:23 +0530 Subject: [PATCH 23/42] Added logs for debugging --- lib/middlewareMethods/Common.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/middlewareMethods/Common.js b/lib/middlewareMethods/Common.js index e5d8c01..6fb7c65 100644 --- a/lib/middlewareMethods/Common.js +++ b/lib/middlewareMethods/Common.js @@ -31,6 +31,7 @@ class CommonMiddlewares { // 2. Payload formatting const formattedPayload = PayloadFormatterMiddleware.formatPayload(requestBody); + console.log('formattedPayload: ', formattedPayload); requestBody.payload = formattedPayload; // 3. Sanitize body and query @@ -40,11 +41,13 @@ class CommonMiddlewares { // 4. Assign request params decodedParams = AssignParamsMiddleware.assignParams(requestMethod, requestBody, requestQuery); + console.log('decodedParams: ', decodedParams); // 5. Extract slack params const slackParamsResponse = ExtractSlackParamsMiddleware.extractSlackParams(requestBody, internalDecodedParams); requestBody = slackParamsResponse.requestBody; internalDecodedParams = slackParamsResponse.internalDecodedParams; + console.log('internalDecodedParams: ', internalDecodedParams); // 6. Validate raw body params await authenticator.validateRawBodyParams(requestRawBody); From 7fd82a95cf8872cefbe4e9d635238c309bb53fb7 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Wed, 14 Feb 2024 13:41:18 +0530 Subject: [PATCH 24/42] Removed logs added for debugging --- middlewares/authentication/Signature.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/middlewares/authentication/Signature.js b/middlewares/authentication/Signature.js index 1a2c71b..634d8ec 100644 --- a/middlewares/authentication/Signature.js +++ b/middlewares/authentication/Signature.js @@ -19,22 +19,16 @@ class ValidateSlackSignature { constructor(params) { const oThis = this; - console.log('type of params.requestBody: ------- ', typeof params.requestBody); - const requestBody = params.requestBody; oThis.requestRawBody = params.requestRawBody; oThis.requestHeaders = params.requestHeaders; - console.log('requestBody.payload: ------- ', requestBody.payload); if (requestBody.payload) { const parsedPayload = JSON.parse(requestBody.payload); - console.log('parsedPayload.api_app_id: ------- ', parsedPayload.api_app_id); oThis.apiAppId = parsedPayload.api_app_id; } else { oThis.apiAppId = requestBody.api_app_id; } - - console.log('oThis.apiAppId: ------- ', oThis.apiAppId); } /** @@ -98,20 +92,13 @@ class ValidateSlackSignature { async _validateSignature(requestTimestamp, version, signature) { const oThis = this; - console.log('oThis.requestRawBody: ------- ', oThis.requestRawBody); const signingSecret = slackAppConstants.getSigningSecretForAppId(oThis.apiAppId); - console.log('signingSecret: ------- ', signingSecret); - const signatureString = `${version}:${requestTimestamp}:${oThis.requestRawBody}`; const computedSignature = crypto .createHmac('sha256', signingSecret) .update(signatureString, 'utf8') .digest('hex'); - - console.log('signatureString: ------- ', signatureString); - console.log('computedSignature: ------- ', computedSignature); - console.log('signature: ------- ', signature); if (!crypto.timingSafeEqual(Buffer.from(signature, 'utf-8'), Buffer.from(computedSignature, 'utf-8'))) { console.error(`Invalid signature :: ${signature}`); From a54c8d16069fd418ef88dafa2ed47087606e808b Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Thu, 15 Feb 2024 18:56:26 +0530 Subject: [PATCH 25/42] Added date picker and static select to modal --- lib/slack/Modal.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index b882e67..78e97e8 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -158,6 +158,91 @@ class Modal { oThis.viewJSON.blocks.push(textboxJSON); } + /** + * Add date picker element to modal. + * + * @param {string} labelText + * @param {string} [initialDate] + * @param {string} [placeHolderText] + */ + addDatePicker(labelText, initialDate = '1990-04-28', placeHolderText = 'Select a date') { + const oThis = this; + + const datePickerJson = { + type: 'section', + text: { + type: 'mrkdwn', + text: labelText + }, + accessory: { + type: 'datepicker', + initial_date: initialDate, + placeholder: { + type: 'plain_text', + text: placeHolderText, + emoji: true + } + } + }; + + oThis.viewJSON.blocks.push(datePickerJson); + } + + /** + * Add static select to modal. + * + * @param {string} labelText + * @param {string} optionsArray + * @param {string} defaultOption + * @param {string} placeholderText + */ + addStaticSelect(labelText, optionsArray, defaultOption = {}, placeholderText = 'Select an item') { + const oThis = this; + + const staticSelectJson = { + type: 'section', + text: { + type: 'mrkdwn', + text: labelText + }, + accessory: { + type: 'static_select', + placeholder: { + type: 'plain_text', + text: placeholderText, + emoji: true + }, + options: [], + } + }; + + for (let index = 0; index < optionsArray.length; index++) { + const currOption = optionsArray[index]; + + staticSelectJson.accessory.options.push({ + text: { + type: 'plain_text', + text: currOption.text, + emoji: true + }, + value: currOption.value + }); + } + + if (optionsArray.length === 0) { + if (!CommonValidators.validateNonEmptyObject(defaultOption)) { + defaultOption = { + 'type': 'plain_text', + 'text': '*this is plain_text text*', + 'emoji': true + } + } + staticSelectJson.accessory.options.push(defaultOption); + } + + oThis.viewJSON.blocks.push(staticSelectJson); + } + /** * Add check boxes to modal. * From 496ad4d4f7d54998b2c4b0409f51ed72042e2135 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Thu, 15 Feb 2024 19:08:23 +0530 Subject: [PATCH 26/42] Fix --- lib/slack/Modal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index 78e97e8..2c7dc8d 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -196,7 +196,7 @@ class Modal { * @param {string} defaultOption * @param {string} placeholderText */ - addStaticSelect(labelText, optionsArray, defaultOption = {}, placeholderText = 'Select an item') { + addStaticSelect(labelText, optionsArray = [], defaultOption = {}, placeholderText = 'Select an item') { const oThis = this; const staticSelectJson = { From eaebd315805ef7a205e99a4a935a756645cb1745 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Thu, 15 Feb 2024 19:13:57 +0530 Subject: [PATCH 27/42] Fix --- lib/slack/Modal.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index 2c7dc8d..62f12a6 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -232,9 +232,9 @@ class Modal { if (optionsArray.length === 0) { if (!CommonValidators.validateNonEmptyObject(defaultOption)) { defaultOption = { - 'type': 'plain_text', - 'text': '*this is plain_text text*', - 'emoji': true + type: 'plain_text', + text: '*this is plain_text text*', + emoji: true } } staticSelectJson.accessory.options.push(defaultOption); From f681dc08149e5760e5d8c5ca7b4b95700cda06ab Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Thu, 15 Feb 2024 19:46:35 +0530 Subject: [PATCH 28/42] Added default value --- lib/slack/Modal.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index 62f12a6..a58b4bf 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -232,9 +232,12 @@ class Modal { if (optionsArray.length === 0) { if (!CommonValidators.validateNonEmptyObject(defaultOption)) { defaultOption = { - type: 'plain_text', - text: '*this is plain_text text*', - emoji: true + text: { + type: 'plain_text', + text: 'this is plain_text text', + emoji: true + }, + value: 'default-value' } } staticSelectJson.accessory.options.push(defaultOption); From edc09bc0024debb67575a4e61bf22c969e9cccdb Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 11:41:06 +0530 Subject: [PATCH 29/42] Stringified payload --- lib/middlewareMethods/Common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middlewareMethods/Common.js b/lib/middlewareMethods/Common.js index 6fb7c65..4d765e4 100644 --- a/lib/middlewareMethods/Common.js +++ b/lib/middlewareMethods/Common.js @@ -31,7 +31,7 @@ class CommonMiddlewares { // 2. Payload formatting const formattedPayload = PayloadFormatterMiddleware.formatPayload(requestBody); - console.log('formattedPayload: ', formattedPayload); + console.log('formattedPayload: ', JSON.stringify(formattedPayload)); requestBody.payload = formattedPayload; // 3. Sanitize body and query From 84fdb4684d324ba7d11898b45f4c4220645b1f16 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 11:58:33 +0530 Subject: [PATCH 30/42] Date picker type changed to input from section --- lib/slack/Modal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index a58b4bf..200a425 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -169,7 +169,7 @@ class Modal { const oThis = this; const datePickerJson = { - type: 'section', + type: 'input', text: { type: 'mrkdwn', text: labelText From dbb223b8e9408662301bdc88accbbb514f70d478 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 12:08:51 +0530 Subject: [PATCH 31/42] Updated datepicker modal --- lib/slack/Modal.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index 200a425..b43733d 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -170,11 +170,8 @@ class Modal { const datePickerJson = { type: 'input', - text: { - type: 'mrkdwn', - text: labelText - }, - accessory: { + block_id: 'date_picker_block', + element: { type: 'datepicker', initial_date: initialDate, placeholder: { @@ -182,6 +179,11 @@ class Modal { text: placeHolderText, emoji: true } + }, + label: { + type: 'plain_text', + text: labelText, + emoji: true } }; From 698a9bc6f52b955a1909b092be04c68f1ecd48e6 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 12:18:14 +0530 Subject: [PATCH 32/42] Removed block id from datepicker --- lib/slack/Modal.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index b43733d..f07571b 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -170,7 +170,6 @@ class Modal { const datePickerJson = { type: 'input', - block_id: 'date_picker_block', element: { type: 'datepicker', initial_date: initialDate, From 149abd38e71294665438bed76460eabcfcab4ddd Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 12:29:05 +0530 Subject: [PATCH 33/42] Added datepicker value --- lib/slack/ParseViewActionsApiParams.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/slack/ParseViewActionsApiParams.js b/lib/slack/ParseViewActionsApiParams.js index eb133c7..577d199 100644 --- a/lib/slack/ParseViewActionsApiParams.js +++ b/lib/slack/ParseViewActionsApiParams.js @@ -175,9 +175,14 @@ class ParseBlockActionsApiParams { oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_option.value; break; } + case 'datepicker': { + oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_date; + } default: // Do nothing; } + + console.log('oThis.finalResponse: ------', oThis.finalResponse); } } From 07b3fcd340028141c70635c279bbd57ab887fe51 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 12:38:14 +0530 Subject: [PATCH 34/42] Static select to use input --- lib/slack/Modal.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/slack/Modal.js b/lib/slack/Modal.js index f07571b..bbecf75 100644 --- a/lib/slack/Modal.js +++ b/lib/slack/Modal.js @@ -201,26 +201,27 @@ class Modal { const oThis = this; const staticSelectJson = { - type: 'section', - text: { - type: 'mrkdwn', - text: labelText - }, - accessory: { + type: 'input', + element: { type: 'static_select', placeholder: { type: 'plain_text', text: placeholderText, emoji: true }, - options: [], + options: [] + }, + label: { + type: 'plain_text', + text: labelText, + emoji: true } }; for (let index = 0; index < optionsArray.length; index++) { const currOption = optionsArray[index]; - staticSelectJson.accessory.options.push({ + staticSelectJson.element.options.push({ text: { type: 'plain_text', text: currOption.text, @@ -241,7 +242,7 @@ class Modal { value: 'default-value' } } - staticSelectJson.accessory.options.push(defaultOption); + staticSelectJson.element.options.push(defaultOption); } oThis.viewJSON.blocks.push(staticSelectJson); From f6b593ea83ed61281a2b0fb7be70ad53dacabf25 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 13:20:16 +0530 Subject: [PATCH 35/42] Added static select to parse view params --- lib/slack/ParseViewActionsApiParams.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/slack/ParseViewActionsApiParams.js b/lib/slack/ParseViewActionsApiParams.js index 577d199..498f2de 100644 --- a/lib/slack/ParseViewActionsApiParams.js +++ b/lib/slack/ParseViewActionsApiParams.js @@ -178,6 +178,9 @@ class ParseBlockActionsApiParams { case 'datepicker': { oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_date; } + case 'static_select': { + oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_option.value + } default: // Do nothing; } From 3b58a5ef3d9ad9eea6c301922bf8d84ff9c69987 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 15:04:51 +0530 Subject: [PATCH 36/42] Added logs for debugging --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 696a7df..9a626cd 100644 --- a/index.js +++ b/index.js @@ -95,6 +95,7 @@ class SlackAdmin { next(); } catch (err) { + console.log('Error in interactive endpoint middleware:', err); console.error('Interactive endpoint middleware error:', JSON.stringify(err)); return res.status(200).json('something_went_wrong'); } From 090d4873d31ddcb7a8a46e2393385ee9ec32d292 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 15:11:03 +0530 Subject: [PATCH 37/42] Switch case fix --- lib/slack/ParseViewActionsApiParams.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/slack/ParseViewActionsApiParams.js b/lib/slack/ParseViewActionsApiParams.js index 498f2de..68bff12 100644 --- a/lib/slack/ParseViewActionsApiParams.js +++ b/lib/slack/ParseViewActionsApiParams.js @@ -177,6 +177,7 @@ class ParseBlockActionsApiParams { } case 'datepicker': { oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_date; + break; } case 'static_select': { oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_option.value From 3d52d6017dc8ebb4a2c3e69d41cefacdd69e25b1 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 15:11:31 +0530 Subject: [PATCH 38/42] Switch case fix --- lib/slack/ParseViewActionsApiParams.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/slack/ParseViewActionsApiParams.js b/lib/slack/ParseViewActionsApiParams.js index 68bff12..4b2e7ba 100644 --- a/lib/slack/ParseViewActionsApiParams.js +++ b/lib/slack/ParseViewActionsApiParams.js @@ -180,7 +180,8 @@ class ParseBlockActionsApiParams { break; } case 'static_select': { - oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_option.value + oThis.finalResponse.apiParams[relevantParameter] = stateObject.selected_option.value; + break; } default: // Do nothing; From 6084777bd528c574ad87512f25d67eb4d27524da Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 15:21:51 +0530 Subject: [PATCH 39/42] Removed logs added for debugging --- lib/slack/ParseViewActionsApiParams.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/slack/ParseViewActionsApiParams.js b/lib/slack/ParseViewActionsApiParams.js index 4b2e7ba..7777b93 100644 --- a/lib/slack/ParseViewActionsApiParams.js +++ b/lib/slack/ParseViewActionsApiParams.js @@ -186,8 +186,6 @@ class ParseBlockActionsApiParams { default: // Do nothing; } - - console.log('oThis.finalResponse: ------', oThis.finalResponse); } } From f213ac876244732bfe60fdf9066c40502c2e43de Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 16:06:20 +0530 Subject: [PATCH 40/42] Do not replace original message --- lib/helpers/messageHelper.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/helpers/messageHelper.js b/lib/helpers/messageHelper.js index 8b909be..860e457 100644 --- a/lib/helpers/messageHelper.js +++ b/lib/helpers/messageHelper.js @@ -44,7 +44,8 @@ class SlackHelper { const messageObject = { response_type: responseType, text: text || '', - blocks: blocks + blocks: blocks, + replace_original: false }; const httpLibObj = new HttpLibrary({ resource: responseUrl, noFormattingRequired: true }); From d166e98cc9992bf7fb08675aef243557e1c40906 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 16:10:03 +0530 Subject: [PATCH 41/42] Replace original moved to param --- lib/helpers/messageHelper.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/helpers/messageHelper.js b/lib/helpers/messageHelper.js index 860e457..8cd099a 100644 --- a/lib/helpers/messageHelper.js +++ b/lib/helpers/messageHelper.js @@ -20,6 +20,7 @@ class SlackHelper { * @param {string} params.text * @param {array} [params.blocks] * @param {string} params.responseUrl + * @param {boolean} [params.replaceOriginal] * * @returns {Promise} */ @@ -28,6 +29,7 @@ class SlackHelper { const text = params.text; const responseUrl = params.responseUrl; const blocks = params.blocks || []; + const replaceOriginal = params.replaceOriginal || false; if (!responseUrl) { return Promise.reject( @@ -45,7 +47,7 @@ class SlackHelper { response_type: responseType, text: text || '', blocks: blocks, - replace_original: false + replace_original: replaceOriginal }; const httpLibObj = new HttpLibrary({ resource: responseUrl, noFormattingRequired: true }); From eccc4f3adc2ea38fa5cd8cf6b3d3f3929c12e557 Mon Sep 17 00:00:00 2001 From: Kiran Kamalakar Date: Fri, 16 Feb 2024 18:37:26 +0530 Subject: [PATCH 42/42] Removed logs added for debugging --- lib/middlewareMethods/Common.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/middlewareMethods/Common.js b/lib/middlewareMethods/Common.js index 4d765e4..e5d8c01 100644 --- a/lib/middlewareMethods/Common.js +++ b/lib/middlewareMethods/Common.js @@ -31,7 +31,6 @@ class CommonMiddlewares { // 2. Payload formatting const formattedPayload = PayloadFormatterMiddleware.formatPayload(requestBody); - console.log('formattedPayload: ', JSON.stringify(formattedPayload)); requestBody.payload = formattedPayload; // 3. Sanitize body and query @@ -41,13 +40,11 @@ class CommonMiddlewares { // 4. Assign request params decodedParams = AssignParamsMiddleware.assignParams(requestMethod, requestBody, requestQuery); - console.log('decodedParams: ', decodedParams); // 5. Extract slack params const slackParamsResponse = ExtractSlackParamsMiddleware.extractSlackParams(requestBody, internalDecodedParams); requestBody = slackParamsResponse.requestBody; internalDecodedParams = slackParamsResponse.internalDecodedParams; - console.log('internalDecodedParams: ', internalDecodedParams); // 6. Validate raw body params await authenticator.validateRawBodyParams(requestRawBody);