Migrate send message serverless endpoints into lambdas/account-scoped#3973
Migrate send message serverless endpoints into lambdas/account-scoped#3973stephenhand merged 5 commits intomasterfrom
Conversation
…onversation folder Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
stephenhand
left a comment
There was a problem hiding this comment.
Fix the linter error raised in the last CI run
Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Fixed in commit |
stephenhand
left a comment
There was a problem hiding this comment.
Uppdate the existing logs and add extra logs in this PR to aid debugging in accordance with the coding standards. Replace console.log calls with methods appropriate to the level the logs should be
Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Done in commit
Security Summary: No security vulnerabilities found (CodeQL scan returned 0 alerts). |
stephenhand
left a comment
There was a problem hiding this comment.
Add a feature flag to plugin-hrm-form called use_twilio_lambda_to_send_messages
Use this flag to determine whether the sendSystemMessage method in ServerlessService.ts should send to the legacy endpoint or the migrated endpoint. It should send to the migrated endpoint if set
Move sendSystemMessage our of ServerlessService.ts to a new twilioConversationService.ts file in the same directory
…emMessage to twilioConversationService.ts Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Done in commit
|
Ports three Twilio Serverless functions (
sendSystemMessage,sendStudioMessage,sendMessageAndRunJanitor) intolambdas/account-scoped/src/conversation/, following the same migration patterns asgetTaskAndReservations. Adds a feature flag inplugin-hrm-formto gate the new lambda endpoint forsendSystemMessage.Description
Lambda changes (
lambdas/account-scoped)conversation/sendSystemMessage.ts— Sends a system message to a conversation, chat channel, or a task's associated channel. Replacescontext.*env vars withgetChatServiceSid/getWorkspaceSidlookups; returnsResult<HttpError, any>instead of serverless callback. Registered withvalidateFlexTokenRequest({ tokenMode: 'agent' })(wasTokenValidator-wrapped).conversation/sendStudioMessage.ts— Removes the studio webhook on a channel before callingsendSystemMessageto prevent Studio re-triggering. Registered withvalidateWebhookRequest(was.protected.ts).conversation/sendMessageAndRunJanitor.ts— Removes studio webhooks, sends a system message, then runschatChannelJanitorto close the conversation/channel. Supports bothconversationSidandchannelSidpaths. Registered withvalidateWebhookRequest(was.protected.ts).router.ts— Adds three new routes underconversation/sendSystemMessage,conversation/sendStudioMessage, andconversation/sendMessageAndRunJanitor.Unit tests added for all three handlers covering validation errors, happy paths, and error propagation.
Logging — Replaced
console.logcalls with appropriate log level methods (console.debugfor entry points and verbose tracing,console.infofor key operations/milestones,console.errorfor unexpected failures). Added extra debug and info logs to all three handlers to aid debugging in production.Plugin changes (
plugin-hrm-form)types/FeatureFlags.ts— Addeduse_twilio_lambda_to_send_messagesfeature flag.services/twilioConversationService.ts(new file) — ContainssendSystemMessage, moved here fromServerlessService.ts. Whenuse_twilio_lambda_to_send_messagesis enabled, calls the migrated lambda endpoint (/conversation/sendSystemMessage); otherwise falls back to the legacy serverless endpoint (/sendSystemMessage).services/ServerlessService.ts— RemovedsendSystemMessage(moved totwilioConversationService.ts).utils/setUpActions.ts— Updated import ofsendSystemMessageto use the newtwilioConversationService.Checklist
Other Related Issues
None
Verification steps
Deploy and invoke each endpoint via the account-scoped Lambda path:
POST /lambda/twilio/account-scoped/{accountSid}/conversation/sendSystemMessagewith a valid Flex token and aconversationSid/channelSid/taskSid+messagePOST /lambda/twilio/account-scoped/{accountSid}/conversation/sendStudioMessagewith a Twilio-signed request and achannelSid+messagePOST /lambda/twilio/account-scoped/{accountSid}/conversation/sendMessageAndRunJanitorwith a Twilio-signed request and aconversationSidorchannelSid+message— verify the conversation/channel is deactivated after the callTo test the feature flag routing in
plugin-hrm-form:use_twilio_lambda_to_send_messages: truein the service configuration feature flags and verifysendSystemMessagecalls route to the lambda endpointfalse, verifysendSystemMessagecalls route to the legacy serverless endpointAFTER YOU MERGE
You are responsible for ensuring the above steps are completed. If you move a ticket into QA without advising what version to test, the QA team will assume the latest tag has the changes. If it does not, the following confusion is on you! :-P
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.