Skip to content

chore: Move chatbot handlers to Lambda [CHI-3218] #2929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

GPaoloni
Copy link
Collaborator

@GPaoloni GPaoloni commented Apr 18, 2025

This PR is related to techmatters/serverless#757 and https://github.com/techmatters/infrastructure-config/compare/master...gian_CHI-3218.

Description

This PR migrates all the chatbot handlers to the account scoped Twilio Lambda.

  • Exposes 3 new endpoints, analogous to those from Serverless
    • captureChannelWithBot (/lambda/twilio/account-scoped/{accountSid}/channelCapture/captureChannelWithBot).
    • chatbotCallback (/lambda/twilio/account-scoped/{accountSid}/channelCapture/chatbotCallback).
    • chatbotCallbackCleanup (/lambda/twilio/account-scoped/{accountSid}/channelCapture/chatbotCallbackCleanup).
  • Adds postSurveyListener, a taskrouter event listener to trigger post survey.

Migration

To Lex v2 migration, refer to techmatters/serverless#756.

  • Ensure https://github.com/techmatters/infrastructure-config/pull/440 is applied in the target environment.
  • Change Studio flow
    • Create a new Make HTTP Request widget with the following configuration:
      • Name: captureChannelWithBot.
      • Method: POST.
      • URL: <hrm base url>/lambda/twilio/account-scoped/{%if trigger.conversation%}{{trigger.conversation.AccountSid}}{%else%}{{trigger.message.AccountSid}}{%endif%}/channelCapture/captureChannelWithBot.
      • Content type: Application/JSON.
      • Request body:
          {
            "channelSid": "{{flow.channel.address}}",
            "message": "Incoming webchat contact",
            "studioFlowSid": "{{flow.flow_sid}}",
            "language": "{{widgets.variables.language}}",
            "botSuffix": "pre_survey",
            "triggerType": "withUserMessage",
            "releaseType": "triggerStudioFlow",
            "releaseFlag": "preSurveyComplete",
            "isConversation": {{widgets.variables.isConversation}},
            "channelType": "{{widgets.variables.channelType}}"
          }
        
    • Create a new Make HTTP Request widget with the following configuration:
      • Name: chatbotCallbackCleanup2.
      • Method: POST.
      • URL: <hrm base url>/lambda/twilio/account-scoped/{%if trigger.conversation%}{{trigger.conversation.AccountSid}}{%else%}{{trigger.message.AccountSid}}{%endif%}/channelCapture/chatbotCallbackCleanup.
      • Content type: Application/JSON.
      • Request body:
          {
            "channelSid": "{{flow.channel.address}}"
          }
        
    • Connect the newly created widgets replacing the old ones used for the channel capture (remember to keep the safeguard that redirects a chat to Flex if the channel capture and/or cleanup fail).
  • Enable enable_lambda_post_survey_processing
    feature flag.

Checklist

Other Related Issues

None

Verification steps

AFTER YOU MERGE

  1. Cut a release tag using the Github workflow. Wait for it to complete and notify in the #aselo-deploys Slack channel.
  2. Comment on the ticket with the release tag version AND any additional instructions required to configure an environment to test the changes.
  3. Only then move the ticket into the QA column in JIRA

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

@GPaoloni GPaoloni changed the title Gian chi 3218 chore: Move chatbot handlers from to Lambda [CHI-3218] Apr 24, 2025
@GPaoloni GPaoloni marked this pull request as ready for review April 25, 2025 21:29
@GPaoloni GPaoloni requested a review from stephenhand April 25, 2025 21:29
@GPaoloni GPaoloni changed the title chore: Move chatbot handlers from to Lambda [CHI-3218] chore: Move chatbot handlers to Lambda [CHI-3218] Apr 30, 2025
Copy link
Collaborator

@stephenhand stephenhand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nitpick about using the correct identifier types.

Honestly I didn't look in detail at the lex implementation itself, just more at how it's integrated into the lambda, which looks good

import { ErrorResult, newErr, newOk, Result } from '../Result';
import { HttpClientError } from '../httpErrors';

import { HrmAccountId, inferAccountSidFromHrmAccountId } from './hrmAccountId';

const requestFromInternalHrmEndpoint = async <TRequest, TResponse>(
hrmAccountId: HrmAccountId,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the correct type

memory: LexMemory;
controlTask: TaskInstance;
controlTaskAttributes: any;
accountSid: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use correct type

Copy link
Collaborator

@stephenhand stephenhand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the types niggle, otherwise looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants