Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

CELA_DEV to prodmerge to CELA_PROD #77

Open
wants to merge 25 commits into
base: cela-prod
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sdk/custom/intents/current_book.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trainingPhrases:
- Reprendre ma lecture
- Reprends ma lecture
- Reprends
- Reprends le dernier livre
- Reprends la lecture
- Reprendre la lecture
- Reprendre
5 changes: 5 additions & 0 deletions sdk/custom/intents/en/current_book.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trainingPhrases:
- Resume
- Resume reading
- Resume playback
- resume the last book
4 changes: 0 additions & 4 deletions sdk/custom/intents/en/recent_books.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
trainingPhrases:
- resume reading
- last book
- play the last book
- resume the last book
- resume
- last books
- recent
- resume playings
- recent books
6 changes: 6 additions & 0 deletions sdk/custom/intents/en/search.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
trainingPhrases:
- search for a book
- search for a book by ($query 'Ernest Hemingway' auto=false)
- I want to search for a book
- search for a specific book
- I am looking for ($query 'The Little Prince by Antoine de Saint-Exupéry' auto=false)
- search
- find
- search for
- I am looking for a book ($query 'The Little Prince by Antoine de Saint-Exupéry'
Expand Down
5 changes: 0 additions & 5 deletions sdk/custom/intents/recent_books.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
trainingPhrases:
- mes livres récents
- reprends
- reprendre ma lecture
- reprendre la lecture
- derniers livres
- livres récents
- voir mes derniers livres
- voir mes livres récents
- reprendre ma lecture
- reprendre la lecture
- derniers livres lus
3 changes: 3 additions & 0 deletions sdk/custom/scenes/home_user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ intentEvents:
- handler:
webhookHandler: home_user__intent__recent_books
intent: recent_books
- handler:
webhookHandler: home_user__intent__current_book
intent: current_book
- handler:
webhookHandler: home_user__intent__fallback
intent: actions.intent.NO_MATCH_1
Expand Down
1 change: 1 addition & 0 deletions sdk/webhooks/ActionsOnGoogleFulfillment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ handlers:
- name: player_prequel__intent__no
- name: home_user__intent__recent_books
- name: info__intent__no
- name: home_user__intent__current_book
httpsEndpoint:
baseUrl: https://us-central1-cela-1.cloudfunctions.net/ActionsOnGoogleFulfillment
endpointApiVersion: 2
68 changes: 38 additions & 30 deletions webhooks/functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webhooks/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.16.0",
"i18next": "^21.5.3",
"opds-fetcher-parser": "git+https://github.com/edrlab/opds_fetcher_parser.git#f74c1bfbaccc7508de2445bb16aacc8bd6ad9641",
"opds-fetcher-parser": "git+https://github.com/edrlab/opds_fetcher_parser.git#be1b96f67499102675676b03a5aee4d267924972",
"reflect-metadata": "^0.1.13",
"validator": "^13.7.0"
},
Expand Down
4 changes: 2 additions & 2 deletions webhooks/functions/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

export let NAME = "";
export const NAME_EN = "CELA";
export const NAME_FR = "CAEB";
export const NAME_FR = "<sub alias=\"ka hèbe\">CAÉB</sub>";
export const setName = (lang: TLang) => NAME = lang === 'fr' ? NAME_FR : NAME_EN;

export const API_BASE_URL = "https://training1.celalibrary.ca/smartspeakerv1/search";
Expand All @@ -20,7 +20,7 @@ export const PADDING_GROUP = 5;
export const PADDING_PUB = 3;
export const LAST_SEEN_THRESHOLD = 72;

export const PROJECT_ID = 'cela-1';
export const PROJECT_ID = 'cela-2';


export type TLang = 'fr' | 'en';
Expand Down
18 changes: 13 additions & 5 deletions webhooks/functions/src/controller/Machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {MediaType, OptionalMediaControl} from '@assistant/conversation/dist/api/
import {IOpdsLinkView, IOpdsPublicationView, IOpdsResultView} from 'opds-fetcher-parser/build/src/interface/opds';
import {TSdkHandler} from '../typings/sdkHandler';
import {WebpubError} from '../error';
import {stall} from '../tools';
import {IWebPubView} from 'opds-fetcher-parser/build/src/interface/webpub';

export class Machine {
private _conv: IConversationV3;
Expand Down Expand Up @@ -85,7 +87,7 @@ export class Machine {
}

if (this._sayAcc) {
if (/.*<.*>.*<\/.*>.*/.test(this._sayAcc)) {
if (/.*<.*>.*/.test(this._sayAcc)) {
this._sayAcc = '<speak>' + this._sayAcc + '</speak>';
}
console.info('SAY: ', this._sayAcc);
Expand Down Expand Up @@ -218,6 +220,12 @@ export class Machine {

public isCurrentlyPlaying() {
const {url, time, index} = this.playerCurrent;
// if (!playing) {
// return false; // @TODO: need to define the use of this boolean
// }
if (url === undefined || time === undefined || index === undefined) {
return false;
}
if (!this.isValidHttpUrl(url)) {
throw new Error('not valid playing url');
}
Expand Down Expand Up @@ -559,7 +567,7 @@ export class Machine {
);
}

private async webpubRequest(url: string) {
private webpubRequest: (url: string) => Promise<IWebPubView> = stall(async (url: string) => {
if (!validator.isURL(url)) {
throw new Error('url not valid : ' + url);
}
Expand All @@ -574,9 +582,9 @@ export class Machine {
error.code = 401;
throw error;
}
}
});

private async feedRequest(url: string) {
private feedRequest: (url: string) => Promise<IOpdsResultView> = stall(async (url: string) => {
if (!this._fetcher) {
throw new Error('no fetcher available !');
}
Expand Down Expand Up @@ -625,7 +633,7 @@ export class Machine {
console.error('FETCHER ERROR END');
}
return feed;
}
});

private removeSessionDataWhenNewUserSession() {
if (!this._model) {
Expand Down
20 changes: 17 additions & 3 deletions webhooks/functions/src/controller/handler/home_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const home_user = (app: Assistant) => {
app.handle("home_user__intent__silence", help);
app.handle("home_user__intent__silence_end", missing);
app.handle("home_user__intent__recent_books", recentBooks);
app.handle("home_user__intent__current_book", currentBook);

}

Expand Down Expand Up @@ -58,13 +59,13 @@ const enter: THandlerFn = async (m) => {
}
m.say("home_user.enter.playing.3");
m.say("home_user.enter.regular.1");
m.say("home_user.enter.regular.2");
// m.say("home_user.enter.regular.2");

} else if (regularUser) {
// regularUser

m.say("home_user.enter.regular.1");
m.say("home_user.enter.regular.2");
// m.say("home_user.enter.regular.2");
} else {
// occasionalUser

Expand Down Expand Up @@ -109,6 +110,19 @@ const recentBooks: THandlerFn = (m) => {
})
}

const currentBook: THandlerFn = (m) => {

const isPlaying = m.isCurrentlyPlaying();
if (isPlaying) {

m.nextScene = 'player_prequel';
} else {

m.say('home_user.currentBook.1');
m.nextScene = 'home_user';
}
}

const help: THandlerFn = (m) => {

m.setSessionState("home_user", "REPEAT");
Expand All @@ -120,4 +134,4 @@ const repeat: THandlerFn = (m) => {

m.setSessionState("home_user", "REPEAT");
m.nextScene = "home_user";
}
}
16 changes: 9 additions & 7 deletions webhooks/functions/src/controller/handler/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,23 @@ export const enter: THandlerFn = async (m) => {
// redirect to nextScene 'selection' for group
// or 'player-prequel' for a publication

const nextLink = kind === "GROUP" ? await m.getNexLinkGroupWithUrl(url) : await m.getNexLinkPublicationWithUrl(url);
const nextPageBool = !!nextLink;
if (m.selectionSession.nextUrlCounter) {
const nextLink = kind === "GROUP" ? await m.getNexLinkGroupWithUrl(url) : await m.getNexLinkPublicationWithUrl(url);
if (nextLink) {

} else {
if (!nextLink) {
if (kind === "GROUP") {
m.say("selection.enter.lastPage.group");
} else {
m.say("selection.enter.lastPage.publication");
}
}

} else {

// intro
if (handler === "home_user__intent__bookshelf") {
const {publication} = await m.getPublicationFromFeed(url); // @TODO fix it .. twice call to api
m.say('selection.enter.bookshelf.first', {number: publication.length});
} else if (handler === "home_user__intent__search") {
} else if (handler === "search__on_enter") {
const {length} = await m.getPublicationFromFeed(url); // @TODO fix it .. twice call to api
m.say('selection.enter.search', {number: length});
}
Expand All @@ -74,7 +73,10 @@ export const enter: THandlerFn = async (m) => {
// @TODO handle collection group or publication

// list groups or publication
m.say('selection.enter.common.1', {pageSuivante: ''});
m.say('selection.enter.common.1');
if (nextPageBool) {
m.say('selection.enter.nextPage.1');
}
const list = kind === "GROUP"
? (await m.getGroupsFromFeed(url)).groups.map(({title}) => title)
: (await m.getPublicationFromFeed(url)).publication.map(({title}) => title);
Expand Down
Loading