amazon-connect / amazon-connect-salesforce-lambda

Apache License 2.0
45 stars 34 forks source link

Comprehend sentiment analysis fails for normal length phone calls #20

Closed rectalogic closed 2 years ago

rectalogic commented 3 years ago

The comprehend sentiment analysis lambda fails for a 28min phone call because the detect_sentiment API being uses is limited to 5000 chars.

[ERROR] TextSizeLimitExceededException: An error occurred (TextSizeLimitExceededException) when calling the DetectSentiment operation: Input text size exceeds limit. Max length of request text allowed is 5000 bytes while in this request the text size is 12945 bytes
Traceback (most recent call last):
  File "/var/task/sfProcessTranscriptionResult.py", line 91, in lambda_handler
    raise e
  File "/var/task/sfProcessTranscriptionResult.py", line 73, in lambda_handler
    comprehendResults['FormattedSentiment'] = GetFormattedSentiment(StartComprehendAnalysis(customerTranscripts, 'snt', languageCode, False))
  File "/var/task/sfComprehendUtil.py", line 39, in StartComprehendAnalysis
    cResults = analyzeContactDetail(transcripts, compAnalysis, languageCode)
  File "/var/task/sfComprehendUtil.py", line 73, in analyzeContactDetail
    rComprehend = detectSentiment(comprehend, finalTranscript, languageCode)
  File "/var/task/sfComprehendUtil.py", line 87, in detectSentiment
    rSNT = cObject.detect_sentiment(Text=sentimentText, LanguageCode=languageCode)
  File "/opt/python/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/opt/python/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)

This https://github.com/amazon-connect/amazon-connect-salesforce-lambda/blob/bee2ccc1d92bc259615ce7e9d823e2f78a4f247e/sam-app/lambda_functions/sfComprehendUtil.py#L87 needs to split into multiple 5000 char documents and use the batch_detect_sentiment API like this: https://stackoverflow.com/questions/58344105/how-do-you-filter-documents-by-size-before-sending-to-aws-comprehend-via-boto3

Or at the very least handle the TextSizeLimitExceededException exception - currently this prevents the transcript itself from getting into the salesforce CCA record.

yingdoli commented 3 years ago

Hi, thanks for reporting this. batch_detect_sentiment doesn't return an overall sentiment and sentiment score. I think the better option is to use StartSentimentDetectionJob to handle the job asynchronously. We are working on addressing this and will have the fix soon.

andedavd commented 2 years ago

Hello, we are closing this ticket as we have not been able to replicate and we have not had similar issues reported. However, if this is still an issue, please feel free to reopen this issue or create a new one. Thank you!