Skip to content

Commit

Permalink
Merge branch 'main' into feature/chatbot/CAI-133-chat-error-management
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastiano-Bertolin authored Sep 16, 2024
2 parents c460713 + e5eba2e commit a7e9d99
Show file tree
Hide file tree
Showing 141 changed files with 6,175 additions and 3,067 deletions.
5 changes: 0 additions & 5 deletions .changeset/bright-cycles-reply.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/curvy-rats-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": patch
---

Fix Webinar's bodyContent margins
5 changes: 5 additions & 0 deletions .changeset/cyan-guests-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": minor
---

Add structured data functions and add them to homepage
5 changes: 0 additions & 5 deletions .changeset/gold-coats-glow.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/late-parrots-double.md

This file was deleted.

6 changes: 6 additions & 0 deletions .changeset/many-dancers-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nextjs-website": minor
"storybook-app": minor
---

Show statsSource attribute in Stats component
5 changes: 0 additions & 5 deletions .changeset/polite-bats-own.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/rare-seahorses-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chatbot": minor
---

Indexing interpolates the website url of the correct environment
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"nextjs-website": minor
---

Add tutorial list pages codec
Add CKEditor renderer to NextJS
6 changes: 6 additions & 0 deletions .changeset/silver-experts-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nextjs-website": patch
"storybook-app": minor
---

Fix text alignment when quote is short in Quote component and add "ShortQuote" story to Storybook
5 changes: 5 additions & 0 deletions .changeset/thick-games-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-cms": minor
---

Add Seo component to every entity having a corresponding page
6 changes: 5 additions & 1 deletion .github/actions/build-nextjs-website/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ runs:
with:
path: ${{ github.workspace }}/apps/nextjs-website/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.[jt]s', '**/*.[jt]sx') }}
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.[jt]s') }}-${{ hashFiles('**/*.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-

Expand All @@ -87,6 +87,10 @@ runs:
NEXT_PUBLIC_COGNITO_USER_POOL_ID: ${{ inputs.cognito_user_pool_id }}
NEXT_PUBLIC_COGNITO_IDENTITY_POOL_ID: ${{ inputs.cognito_identity_pool_id }}
NEXT_PUBLIC_CHATBOT_HOST: ${{ inputs.chatbot_host }}
NEXT_PUBLIC_WEBSITE_NAME: ${{ inputs.website_name }}
NEXT_PUBLIC_ORGANIZATION_NAME: ${{ inputs.organization_name }}
NEXT_PUBLIC_ORGANIZATION_LOGO: ${{ inputs.organization_logo }}
NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS: ${{ inputs.organization_social_links }}
NEXT_PUBLIC_CHATBOT_ACTIVE: ${{ inputs.chatbot_active }}
STRAPI_ENDPOINT: ${{ inputs.strapi_endpoint }}
STRAPI_API_TOKEN: ${{ inputs.strapi_api_token }}
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/deploy/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ runs:
NEXT_PUBLIC_COGNITO_USER_POOL_ID: ${{ inputs.cognito_user_pool_id }}
NEXT_PUBLIC_COGNITO_IDENTITY_POOL_ID: ${{ inputs.cognito_identity_pool_id }}
NEXT_PUBLIC_CHATBOT_HOST: ${{ inputs.chatbot_host }}
NEXT_PUBLIC_WEBSITE_NAME: ${{ inputs.website_name }}
NEXT_PUBLIC_ORGANIZATION_NAME: ${{ inputs.organization_name }}
NEXT_PUBLIC_ORGANIZATION_LOGO: ${{ inputs.organization_logo }}
NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS: ${{ inputs.organization_social_links }}
NEXT_PUBLIC_CHATBOT_ACTIVE: ${{ inputs.chatbot_active }}
STRAPI_ENDPOINT: ${{ inputs.strapi_endpoint }}
STRAPI_API_TOKEN: ${{ inputs.strapi_api_token }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/code_review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ jobs:
cognito_identity_pool_id: ${{ secrets.NEXT_PUBLIC_COGNITO_IDENTITY_POOL_ID }}
cognito_app_client_id: ${{ secrets.NEXT_PUBLIC_COGNITO_USER_POOL_WEB_CLIENT_ID }}
chatbot_host: ${{ vars.NEXT_PUBLIC_CHATBOT_HOST }}
website_name: ${{ vars.NEXT_PUBLIC_WEBSITE_NAME }}
organization_name: ${{ vars.NEXT_PUBLIC_ORGANIZATION_NAME }}
organization_logo: ${{ vars.NEXT_PUBLIC_ORGANIZATION_LOGO }}
organization_social_links: ${{ vars.NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS }}
chatbot_active: ${{ vars.NEXT_PUBLIC_CHATBOT_ACTIVE }}
cognito_aws_region: 'eu-south-1'
strapi_endpoint: ${{ vars.STRAPI_ENDPOINT }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/deploy_website.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ jobs:
cognito_identity_pool_id: ${{ secrets.NEXT_PUBLIC_COGNITO_IDENTITY_POOL_ID }}
cognito_app_client_id: ${{ secrets.NEXT_PUBLIC_COGNITO_USER_POOL_WEB_CLIENT_ID }}
chatbot_host: ${{ vars.NEXT_PUBLIC_CHATBOT_HOST }}
website_name: ${{ vars.NEXT_PUBLIC_WEBSITE_NAME }}
organization_name: ${{ vars.NEXT_PUBLIC_ORGANIZATION_NAME }}
organization_logo: ${{ vars.NEXT_PUBLIC_ORGANIZATION_LOGO }}
organization_social_links: ${{ vars.NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS }}
chatbot_active: ${{ vars.NEXT_PUBLIC_CHATBOT_ACTIVE }}
strapi_endpoint: ${{ vars.STRAPI_ENDPOINT }}
strapi_api_token: ${{ secrets.STRAPI_API_TOKEN }}
Expand Down Expand Up @@ -102,6 +106,10 @@ jobs:
cognito_identity_pool_id: ${{ secrets.NEXT_PUBLIC_COGNITO_IDENTITY_POOL_ID }}
cognito_app_client_id: ${{ secrets.NEXT_PUBLIC_COGNITO_USER_POOL_WEB_CLIENT_ID }}
chatbot_host: ${{ vars.NEXT_PUBLIC_CHATBOT_HOST }}
website_name: ${{ vars.NEXT_PUBLIC_WEBSITE_NAME }}
organization_name: ${{ vars.NEXT_PUBLIC_ORGANIZATION_NAME }}
organization_logo: ${{ vars.NEXT_PUBLIC_ORGANIZATION_LOGO }}
organization_social_links: ${{ vars.NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS }}
chatbot_active: ${{ vars.NEXT_PUBLIC_CHATBOT_ACTIVE }}
strapi_endpoint: ${{ vars.STRAPI_ENDPOINT }}
strapi_api_token: ${{ secrets.STRAPI_API_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ jobs:
cognito_identity_pool_id: ${{ secrets.NEXT_PUBLIC_COGNITO_IDENTITY_POOL_ID }}
cognito_app_client_id: ${{ secrets.NEXT_PUBLIC_COGNITO_USER_POOL_WEB_CLIENT_ID }}
chatbot_host: ${{ vars.NEXT_PUBLIC_CHATBOT_HOST }}
website_name: ${{ vars.NEXT_PUBLIC_WEBSITE_NAME }}
organization_name: ${{ vars.NEXT_PUBLIC_ORGANIZATION_NAME }}
organization_logo: ${{ vars.NEXT_PUBLIC_ORGANIZATION_LOGO }}
organization_social_links: ${{ vars.NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS }}
chatbot_active: ${{ vars.NEXT_PUBLIC_CHATBOT_ACTIVE }}
strapi_endpoint: ${{ vars.STRAPI_ENDPOINT }}
strapi_api_token: ${{ secrets.STRAPI_API_TOKEN }}
Expand Down
8 changes: 8 additions & 0 deletions apps/chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ Create a `.env` file inside the folder and write to the file the following envir
AWS_S3_BUCKET=...
AWS_GUARDRAIL_ID=...
AWS_GUARDRAIL_VERSION=...
CHB_REDIS_URL=...
WEBSITE_URL=...

## Knowledge vector database

First of all, verify that the HTML files that compose the Developer Portal documentation exist in a directory. Otherwise create the documentation. Once you have the documentation directory ready, put its path in `params` and, in the end, create the vector index doing:

To reach the remote redis instance, it is necessary to open a tunnel:

./scripts/redis-tunnel.sh

Then, to start the indexing:

python src/modules/create_vector_index.py --params config/params.yaml --use-redis

This script reads the documentation, split it into chucks with gerarchical organization, and stores it on Redis. If the input `--use-redis` is missing, then the index is stored on a AWS S3 bucket.
Expand Down
50 changes: 50 additions & 0 deletions apps/chatbot/scripts/redis-tunnel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Set variables
CLUSTER_NAME="cms-ecs-cluster"
SERVICE_NAME="cms-ecs"
LOAD_BALANCER_NAME="chatbot-load-balancer"
REMOTE_PORT="6379"
LOCAL_PORT="16379"


# Get the ECS Task ARN
TASK_ARN=$(aws ecs list-tasks --cluster $CLUSTER_NAME --service-name $SERVICE_NAME --query 'taskArns[0]' --output text)

if [ -z "$TASK_ARN" ]; then
echo "No ECS task found for the service $SERVICE_NAME in cluster $CLUSTER_NAME."
exit 1
fi

# Extract the Task ID from the Task ARN (last part of the ARN)
TASK_ID=$(basename $TASK_ARN)

if [ -z "$TASK_ID" ]; then
echo "Unable to extract the Task ID from the ARN."
exit 1
fi

# Get the container name (task definition details)
CONTAINER_ID=$(aws ecs describe-tasks --cluster $CLUSTER_NAME --tasks $TASK_ARN --query 'tasks[0].containers[0].runtimeId' --output text)

if [ -z "$CONTAINER_ID" ]; then
echo "No container found for task $TASK_ARN."
exit 1
fi

# Get the Network Load Balancer DNS name
TARGET_HOST=$(aws elbv2 describe-load-balancers --names $LOAD_BALANCER_NAME --query 'LoadBalancers[0].DNSName' --output text)

if [ -z "$TARGET_HOST" ]; then
echo "No Load Balancer found with the name $LOAD_BALANCER_NAME."
exit 1
fi

# Construct the target parameter for SSM for Fargate
TARGET="ecs:${CLUSTER_NAME}_${TASK_ID}_${CONTAINER_ID}"

# Start the SSM session with port forwarding
aws ssm start-session \
--target $TARGET \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters "{\"host\":[\"$TARGET_HOST\"],\"portNumber\":[\"$REMOTE_PORT\"],\"localPortNumber\":[\"$LOCAL_PORT\"]}"
11 changes: 5 additions & 6 deletions apps/chatbot/src/modules/vector_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import tqdm
import logging
import hashlib
import html2text
from bs4 import BeautifulSoup
from selenium import webdriver
from typing import List, Tuple


Expand Down Expand Up @@ -134,11 +137,7 @@ def html2markdown(html):
def create_documentation(
website_url: str,
documentation_dir: str = "./PagoPADevPortal/out/",
) -> Tuple[List[Document], dict]:
from selenium import webdriver
import html2text
from bs4 import BeautifulSoup

) -> Tuple[List[Document], dict]:
if documentation_dir[-1] != "/":
documentation_dir += "/"

Expand Down Expand Up @@ -174,7 +173,7 @@ def create_documentation(

url = file.replace(
documentation_dir,
"https://developer.pagopa.it/"
f"{website_url}/"
).replace(
".html",
""
Expand Down
6 changes: 6 additions & 0 deletions apps/infrastructure/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# infrastructure

## 1.0.0

### Major Changes

- 506f225: Use the rest api gateway and complete the chatbot backend infrastructure scaffolding

## 0.12.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/infrastructure/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "infrastructure",
"version": "0.12.0",
"version": "1.0.0",
"private": true
}
19 changes: 19 additions & 0 deletions apps/infrastructure/src/modules/chatbot/dynamodb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Chatbot queries

module "dynamodb_chatbot_queries" {
source = "git::github.com/terraform-aws-modules/terraform-aws-dynamodb-table.git?ref=715399dbe24f6443820bf5de80f6100b35d56355" # v4.0.0

billing_mode = "PAY_PER_REQUEST"
deletion_protection_enabled = false

name = "${local.prefix}-queries"
hash_key = "id"
server_side_encryption_enabled = true

attributes = [
{
name = "id"
type = "S"
},
]
}
5 changes: 5 additions & 0 deletions apps/nextjs-website/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ NEXT_PUBLIC_CHATBOT_ACTIVE="false"
STRAPI_ENDPOINT="http://127.0.0.1:1337"
STRAPI_API_TOKEN="aStrapiApiToken"
FETCH_FROM_STRAPI="false"
NEXT_PUBLIC_WEBSITE_NAME='DevPortal';
NEXT_PUBLIC_ORGANIZATION_NAME='PagoPA',
NEXT_PUBLIC_ORGANIZATION_LOGO='https://1603831084-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvKmQOwMmwOgFq0L2Rf0Q%2Flogo%2FgCUQ6tWtEoMqS8uZcWOP%2FpagoPA.svg?alt=media&token=2405d6bd-94df-4129-8bcd-8dd0f52272d9',
# each link is separated by a comma
NEXT_PUBLIC_ORGANIZATION_SOCIAL_LINKS='https://x.com/PagoPA,https://www.instagram.com/pagopaspa/,https://www.linkedin.com/company/pagopa/,https://medium.com/pagopa-spa'
25 changes: 25 additions & 0 deletions apps/nextjs-website/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# nextjs-website

## 4.6.0

### Minor Changes

- b40773a: Add bannerLinks to product's overview page in NextJs
- fd090f7: [DPC-298] Update link in overview SEND
- 2fd2d35: Connect product tutorial list page to Strapi content
- 2fd2d35: Add tutorial list pages codec
- 9d2120b: Add version 2.4 of "Manuale dei Servizi"

### Patch Changes

- 9547654: Refactor guides codec
- 7b045c2: Fix Guides page generateStaticParams method
- fe97c1b: Refactor SEO codec, SolutionDetail codec and SolutionTemplateProps
- 95e0cc5: Using id token instead of access token to authenticate api calls
- 46746b4: Add makeProps folder
- 9cb88cf: Refactor homepage codec
- ecb45cc: Refactor ApiDataList and ApiDataListPages codecs
- afc9ecd: Refactor Overviews codec
- c05180d: Refactor Solutions, SolutionListPage and CaseHistories codecs
- ece2b34: Refactor QuickStartGuides codec
- 429a1d5: Refactor webinars codec
- c038519: Refactor guideListPages codec

## 4.5.0

### Minor Changes
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs-website/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-website",
"version": "4.5.0",
"version": "4.6.0",
"private": true,
"scripts": {
"download-docs": "./scripts/fetch-docs.sh docs/from-gitbook",
Expand Down Expand Up @@ -44,6 +44,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-syntax-highlighter": "^15.5.0",
"schema-dts": "^1.1.2",
"swagger-ui": "^5.9.1",
"swiper": "^10.0.3",
"swr": "^2.2.4"
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-website/src/BuildEnv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BuildConfig } from '@/BuildConfig';
import { StrapiEnv } from '@/lib/strapi/StapiEnv';
import { StrapiEnv } from '@/lib/strapi/StrapiEnv';

// BuildEnv
export type BuildEnv = {
Expand Down
28 changes: 22 additions & 6 deletions apps/nextjs-website/src/__tests__/helpers/webinars.helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import { getFutureWebinars, getPastWebinars } from '@/helpers/webinars.helpers';
import { Webinar } from '@/lib/types/webinar';
import { mediaRasterJson } from '@/lib/strapi/__tests__/fixtures/media';

const testWebinar: Webinar = {
title: 'Test Webinar',
description: 'Questo è un webinar di test',
playerSrc: 'https://vimeo.com/event/4135276/embed',
html:
`<h4 style="font-weight: 600; font-size: 24px;">Test Webinar</h4>\n` +
`<p>Questo è un webinar di test</p>\n` +
`<br />\n` +
`<br />\n` +
`<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor enim vel sem fringilla, vitae malesuada nisi malesuada. Sed euismod augue id mauris aliquam, at dapibus lectus laoreet. Sed vel nulla vel risus gravida malesuada ac id tortor. Nulla facilisi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Sed euismod, risus eget bibendum bibendum, quam nisi aliquam nisi, id congue lorem risus id nisi. Sed euismod, risus eget bibendum bibendum, quam nisi aliquam nisi, id congue lorem risus id nisi. Sed euismod, risus eget bibendum bibendum, quam nisi aliquam nisi, id congue lorem risus id nisi.</p>\n`,
bodyContent: [
{
type: 'paragraph',
children: [
{
type: 'text',
text: 'aText',
},
],
},
{
type: 'image',
image: mediaRasterJson.data.attributes,
children: [
{
type: 'text',
text: '',
},
],
},
],
slug: 'test-2024-03-14',
isVisibleInList: false,
imagePath: '/images/webinar-cover-pago-pa-multe-14-marzo.jpg',
Expand Down
4 changes: 4 additions & 0 deletions apps/nextjs-website/src/_contents/appIo/guides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const manualeDeiServizi: GuideDefinition = {
versions: [
{
main: true,
version: 'v2.4',
dirName: 'P38F8u7WrgPJBCks4gpC',
},
{
version: 'v2.3',
dirName: 'zIVHgha5ICXSxcr1Li2Z',
},
Expand Down
Loading

0 comments on commit a7e9d99

Please sign in to comment.