Skip to content
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

fix(web): Update endpoint for IBM Watson to now send feedback to Cloudant #16817

Merged
merged 4 commits into from
Nov 12, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Nov 12, 2024

Update endpoint for IBM Watson to now send feedback to Cloudant

What

  • Sending feedback after using the web chat stopped working a few days ago due to a web service not being present
  • We've been advised by Digital Iceland and Origo to now send feedback to "Cloudant"

I'm basing this off a code snippet that Origo sent us, there they are using the cloudant sdk which is why I added it to package.json

Why

  • This was requested by Digital Iceland
  • The web chat feedback logic is broken today

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration property for chat feedback database.
    • Integrated IBM Cloud's Cloudant service for streamlined feedback submission.
    • Added environment variable configurations for different environments to support chat feedback.
  • Bug Fixes

    • Removed outdated token management logic for feedback submission.
  • Chores

    • Added new dependency for IBM Cloud's Cloudant database service.
    • Enhanced service configurations with new environment variables and initialization processes.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Nov 12, 2024
@RunarVestmann RunarVestmann requested review from a team as code owners November 12, 2024 11:27
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request introduce a new property, chatFeedbackDatabaseName, to the configuration schema in watson-assistant-chat.config.ts, which retrieves its value from an environment variable. Additionally, the WatsonAssistantChatService class in watson-assistant-chat.service.ts has undergone significant modifications, including the removal of the fetch method and the integration of the CloudantV1 service for feedback submission. The package.json file has also been updated to include a new dependency on the @ibm-cloud/cloudant package. Furthermore, new environment variables related to this configuration have been added across various service configuration files.

Changes

File Change Summary
libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.config.ts - Added property chatFeedbackDatabaseName: z.string() to configuration schema.
- Updated load function to include chatFeedbackDatabaseName: env.required('WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME').
libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.service.ts - Removed fetch method and integrated CloudantV1 service.
- Updated submitFeedback method to use postDocument for feedback submission.
- Changed variable type from EnhancedFetchAPI to CloudantV1.
package.json - Added dependency "@ibm-cloud/cloudant": "0.11.0".
apps/api/infra/api.ts - Added new environment variable WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME in the environment configuration object.
charts/islandis/values.dev.yaml - Added new environment variable WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME in service api.
- Added several new environment variables for other services.
charts/islandis/values.prod.yaml - Added new environment variable WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME in service api.
- Introduced initContainer for database migrations in multiple services.
charts/islandis/values.staging.yaml - Added new environment variable WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME in service api.
- Introduced initContainer for database migrations in multiple services.

Possibly related PRs

Suggested reviewers

  • mannipje
  • thordurhhh
  • Toti91

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (2)
libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.config.ts (1)

10-10: LGTM! Consider documenting the new configuration.

The schema addition follows the established pattern and properly validates the new Cloudant database name configuration.

Consider adding a comment or updating the documentation to explain the purpose and requirements of this new configuration property, especially since it's part of the migration to Cloudant.

libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.service.ts (1)

61-64: Explicitly specify fields included in the feedback document

To avoid unintentionally storing sensitive or unnecessary data, consider explicitly specifying the fields from input to include in the document. This enhances security by ensuring only intended data is persisted.

Proposed change:

document: {
  // Specify only the necessary fields
  sessionId: input.sessionId,
  feedbackText: input.feedbackText,
  thumbStatus: thumbStatusToNumberMap[input.thumbStatus],
  timestamp: new Date().toISOString(),
},
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0d7e478 and 23aac9e.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.config.ts (2 hunks)
  • libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.service.ts (3 hunks)
  • package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.config.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (4)
package.json (1)

100-100: Verify security advisories for @ibm-cloud/cloudant.

Let's check for any known security vulnerabilities in the chosen version.

✅ Verification successful

No known security vulnerabilities found for @ibm-cloud/cloudant version 0.11.0.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for security advisories for the @ibm-cloud/cloudant package.

# Check for security advisories using GitHub's GraphQL API
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "@ibm-cloud/cloudant") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

# Check if the package is listed in package-lock.json or yarn.lock
echo "Checking lock files for transitive dependencies..."
rg -A 5 "@ibm-cloud/cloudant" "*lock*"

Length of output: 548


Script:

#!/bin/bash
# Description: Verify the presence of lock files and check for transitive dependencies of @ibm-cloud/cloudant.

# List common lock files
LOCK_FILES=("package-lock.json" "yarn.lock" "pnpm-lock.yaml")

echo "Checking for lock files..."
found_lock_files=0
for lock in "${LOCK_FILES[@]}"; do
  if [[ -f "$lock" ]]; then
    echo "Found lock file: $lock"
    found_lock_files=1
    echo "Searching for @ibm-cloud/cloudant in $lock..."
    rg "@ibm-cloud/cloudant" "$lock"
  fi
done

if [[ $found_lock_files -eq 0 ]]; then
  echo "No lock files found in the repository."
fi

Length of output: 681

libs/api/domains/watson-assistant-chat/src/lib/watson-assistant-chat.service.ts (3)

4-4: Import Cloudant SDK correctly

The Cloudant SDK is correctly imported, allowing for integration with the Cloudant database service.


16-16: Declaration of the Cloudant client instance

Declaring private cloudant: CloudantV1 prepares the service for Cloudant operations and aligns with TypeScript best practices.


68-68: Access response.result.ok correctly

Using response.result.ok correctly accesses the success status from the Cloudant response, conforming to the SDK's response structure.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.44%. Comparing base (ef2427b) to head (e11af70).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16817   +/-   ##
=======================================
  Coverage   36.44%   36.44%           
=======================================
  Files        6853     6853           
  Lines      143479   143479           
  Branches    40949    40949           
=======================================
+ Hits        52287    52290    +3     
+ Misses      91192    91189    -3     
Flag Coverage Δ
air-discount-scheme-backend 54.06% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
api-catalogue-services 77.85% <ø> (ø)
api-domains-air-discount-scheme 37.02% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.60% <ø> (ø)
api-domains-criminal-record 47.48% <ø> (ø)
api-domains-driving-license 44.47% <ø> (ø)
api-domains-education 30.55% <ø> (ø)
api-domains-health-insurance 34.33% <ø> (ø)
api-domains-mortgage-certificate 34.68% <ø> (ø)
api-domains-payment-schedule 41.25% <ø> (ø)
application-api-files 62.45% <ø> (ø)
application-core 70.75% <ø> (-0.32%) ⬇️
application-system-api 40.97% <ø> (ø)
application-template-api-modules 27.62% <ø> (ø)
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.26% <ø> (ø)
application-templates-estate 12.15% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.48% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.22% <ø> (ø)
application-templates-parental-leave 29.83% <ø> (ø)
application-types 6.60% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.82% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 30.20% <ø> (ø)
auth-react 21.84% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.20% <ø> (ø)
clients-driving-license-book 43.44% <ø> (ø)
clients-financial-statements-inao 48.98% <ø> (ø)
clients-license-client 1.26% <ø> (ø)
clients-middlewares 73.47% <ø> (ø)
clients-regulations 42.27% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-rsk-personal-tax-return 38.00% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.19% <ø> (ø)
clients-zendesk 50.37% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 38.89% <ø> (ø)
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.14% <ø> (ø)
contentful-apps 4.69% <ø> (ø)
dokobit-signing 62.58% <ø> (ø)
download-service 44.24% <ø> (ø)
email-service 60.41% <ø> (ø)
feature-flags 90.47% <ø> (ø)
file-storage 45.86% <ø> (ø)
financial-aid-backend 51.26% <ø> (ø)
financial-aid-shared 17.81% <ø> (ø)
icelandic-names-registry-backend 54.34% <ø> (ø)
infra-nest-server 48.37% <ø> (ø)
infra-tracing 43.24% <ø> (ø)
island-ui-core 28.86% <ø> (ø)
judicial-system-api 19.62% <ø> (ø)
judicial-system-audit-trail 68.70% <ø> (ø)
judicial-system-backend 55.18% <ø> (ø)
judicial-system-formatters 79.13% <ø> (ø)
judicial-system-message 66.86% <ø> (ø)
judicial-system-message-handler 47.81% <ø> (ø)
judicial-system-scheduler 70.47% <ø> (ø)
judicial-system-types 43.99% <ø> (ø)
judicial-system-web 27.51% <ø> (ø)
license-api 42.50% <ø> (ø)
localization 10.15% <ø> (ø)
logging 48.43% <ø> (ø)
message-queue 68.58% <ø> (+0.78%) ⬆️
nest-audit 68.20% <ø> (ø)
nest-aws 54.03% <ø> (ø)
nest-config 77.87% <ø> (ø)
nest-core 43.54% <ø> (ø)
nest-feature-flags 50.96% <ø> (ø)
nest-problem 45.82% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
nova-sms 61.90% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 15.89% <ø> (ø)
reference-backend 49.74% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 52.47% <ø> (ø)
services-auth-delegation-api 58.26% <ø> (ø)
services-auth-ids-api 52.08% <ø> (ø)
services-auth-personal-representative 45.56% <ø> (-0.03%) ⬇️
services-auth-personal-representative-public 41.72% <ø> (-0.04%) ⬇️
services-auth-public-api 49.56% <ø> (ø)
services-documents 60.81% <ø> (ø)
services-endorsements-api 53.34% <ø> (ø)
services-sessions 65.39% <ø> (ø)
services-university-gateway 49.31% <ø> (+0.08%) ⬆️
services-user-notification 46.85% <ø> (+<0.01%) ⬆️
services-user-profile 61.84% <ø> (+0.07%) ⬆️
shared-components 26.88% <ø> (ø)
shared-form-fields 31.24% <ø> (ø)
shared-mocking 60.89% <ø> (ø)
shared-pii 92.85% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 27.69% <ø> (ø)
skilavottord-ws 24.14% <ø> (ø)
testing-e2e 66.66% <ø> (ø)
web 1.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef2427b...e11af70. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 12, 2024

Datadog Report

All test runs daf5456 🔗

101 Total Test Services: 0 Failed, 98 Passed
⬆️ Test Sessions change in coverage: 3 increased, 197 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 82 0 31.28s N/A Link
air-discount-scheme-web 0 0 0 2 0 6.95s N/A Link
api 0 0 0 4 0 2.34s N/A Link
api-catalogue-services 0 0 0 23 0 8.99s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 18.89s N/A Link
api-domains-assets 0 0 0 3 0 12.01s N/A Link
api-domains-auth-admin 0 0 0 18 0 12.99s N/A Link
api-domains-communications 0 0 0 5 0 31.24s N/A Link
api-domains-criminal-record 0 0 0 5 0 8.67s N/A Link
api-domains-driving-license 0 0 0 23 0 31.48s N/A Link

@RunarVestmann RunarVestmann requested a review from a team as a code owner November 12, 2024 12:37
Copy link
Member

@robertaandersen robertaandersen left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 23aac9e and b5cc754.

📒 Files selected for processing (4)
  • apps/api/infra/api.ts (1 hunks)
  • charts/islandis/values.dev.yaml (1 hunks)
  • charts/islandis/values.prod.yaml (1 hunks)
  • charts/islandis/values.staging.yaml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/api/infra/api.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (5)
charts/islandis/values.staging.yaml (2)

330-330: Verify Cloudant database access configuration

Ensure that the corresponding Cloudant database credentials and connection details are properly configured in the secrets section.

#!/bin/bash
# Check for related Watson/Cloudant secrets configuration
rg "WATSON.*FEEDBACK" secrets

330-330: Environment variable addition aligns with PR objectives

The addition of WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME with value 'island-is-assistant-feedback' correctly implements the requirement to send feedback to Cloudant database.

✅ Verification successful

All Watson Assistant configurations are consistent

Verified that WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME is properly integrated across staging, development, and production environments. No additional changes required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify if there are any other Watson Assistant related configurations that need to be updated
rg -A 5 "WATSON_ASSISTANT" 

Length of output: 15447

charts/islandis/values.prod.yaml (1)

318-318: LGTM! Verify related Watson Assistant configuration

The addition of WATSON_ASSISTANT_CHAT_FEEDBACK_DB_NAME environment variable aligns with the PR objectives to send feedback to Cloudant. The value appears appropriate for production use.

Let's verify the presence of all required Watson Assistant configuration:

✅ Verification successful

Verified: All related Watson Assistant configurations are present and correctly set up.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for all required Watson Assistant configuration
# Expected: All Watson Assistant related environment variables and secrets should be present

echo "Checking Watson Assistant environment variables..."
rg "WATSON_ASSISTANT_CHAT" -A 1

echo "Checking Watson Assistant secrets..."
rg "watson.*assistant.*" -i

Length of output: 21427

charts/islandis/values.dev.yaml (2)

330-330: Verify related Watson Assistant configuration

The new Cloudant database configuration should have corresponding secrets for authentication. I notice WATSON_ASSISTANT_CHAT_FEEDBACK_API_KEY and WATSON_ASSISTANT_CHAT_FEEDBACK_URL are present in the secrets section, which is good. However, ensure these are properly configured in the secrets management system.

#!/bin/bash
# Check if all required Watson/Cloudant configuration is present
# Look for any Watson/Cloudant related configuration patterns

# Search for Watson/Cloudant related configuration
rg -i "watson|cloudant" -g "!*.yaml"

# Check for any TODO or FIXME comments related to Watson/Cloudant
rg -i "todo|fixme|note" -A 3 -B 3 | rg -i "watson|cloudant"

Also applies to: 1055-1056


330-330: Verify the database name value for security best practices

The hardcoded database name 'island-is-assistant-feedback' could potentially expose information about the system structure. Consider using a more generic name or moving this value to a secret.

apps/api/infra/api.ts Show resolved Hide resolved
Copy link
Member

@baering baering left a comment

Choose a reason for hiding this comment

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

Core files LGTM

@kodiakhq kodiakhq bot merged commit 92d04c8 into main Nov 12, 2024
265 checks passed
@kodiakhq kodiakhq bot deleted the fix/web-watson-assistant-feedback-endpoint branch November 12, 2024 16:08
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
…dant (#16817)

* Update endpoint

* Add env variable

* chore: charts update dirty files

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants