create-scout9 1.0.0-alpha.0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +157 -0
- package/dist/shared.json +204 -0
- package/dist/templates/default/assets/DOT-gitignore +10 -0
- package/dist/templates/default/assets/DOT-npmrc +1 -0
- package/dist/templates/default/files.types=checkjs.json +46 -0
- package/dist/templates/default/files.types=null.json +46 -0
- package/dist/templates/default/files.types=typescript.json +46 -0
- package/dist/templates/default/meta.json +4 -0
- package/dist/templates/default/package.json +13 -0
- package/dist/templates/skeleton/assets/DOT-gitignore +10 -0
- package/dist/templates/skeleton/assets/DOT-npmrc +1 -0
- package/dist/templates/skeleton/files.types=checkjs.json +26 -0
- package/dist/templates/skeleton/files.types=null.json +26 -0
- package/dist/templates/skeleton/files.types=typescript.json +26 -0
- package/dist/templates/skeleton/meta.json +4 -0
- package/dist/templates/skeleton/package.json +14 -0
- package/index.js +161 -0
- package/package.json +37 -0
- package/types/index.d.ts +8 -0
- package/types/internal.d.ts +36 -0
- package/utils.js +70 -0
package/bin.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
|
+
import { bold, cyan, grey, yellow } from 'kleur/colors';
|
|
6
|
+
import { create } from './index.js';
|
|
7
|
+
import { dist, package_manager } from './utils.js';
|
|
8
|
+
|
|
9
|
+
const { version } = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8'));
|
|
10
|
+
let cwd = process.argv[2] || '.';
|
|
11
|
+
|
|
12
|
+
console.log(`${grey(`create-scout9 version ${version}`)}`);
|
|
13
|
+
|
|
14
|
+
p.intro('Welcome to Scout9!');
|
|
15
|
+
|
|
16
|
+
if (cwd === '.') {
|
|
17
|
+
const dir = await p.text({
|
|
18
|
+
message: 'Where should we create your project?',
|
|
19
|
+
placeholder: ' (hit Enter to use current directory)'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (p.isCancel(dir)) process.exit(1);
|
|
23
|
+
|
|
24
|
+
if (dir) {
|
|
25
|
+
cwd = /** @type {string} */ (dir);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (fs.existsSync(cwd)) {
|
|
30
|
+
if (fs.readdirSync(cwd).length > 0) {
|
|
31
|
+
const force = await p.confirm({
|
|
32
|
+
message: 'Directory not empty. Continue?',
|
|
33
|
+
initialValue: false
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// bail if `force` is `false` or the user cancelled with Ctrl-C
|
|
37
|
+
if (force !== true) {
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const options = await p.group(
|
|
44
|
+
{
|
|
45
|
+
template: () =>
|
|
46
|
+
p.select({
|
|
47
|
+
message: 'Which Scout9 app template?',
|
|
48
|
+
// @ts-expect-error i have no idea what is going on here
|
|
49
|
+
options: fs.readdirSync(dist('templates')).map((dir) => {
|
|
50
|
+
const meta_file = dist(`templates/${dir}/meta.json`);
|
|
51
|
+
const { title, description } = JSON.parse(fs.readFileSync(meta_file, 'utf8'));
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
label: title,
|
|
55
|
+
hint: description,
|
|
56
|
+
value: dir
|
|
57
|
+
};
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
|
|
61
|
+
// types: () =>
|
|
62
|
+
// p.select({
|
|
63
|
+
// message: 'Add type checking with TypeScript?',
|
|
64
|
+
// initialValue: /** @type {'checkjs' | 'typescript' | null} */ (null),
|
|
65
|
+
// options: [
|
|
66
|
+
// {
|
|
67
|
+
// label: 'Yes, using JavaScript with JSDoc comments',
|
|
68
|
+
// value: 'checkjs'
|
|
69
|
+
// },
|
|
70
|
+
// {
|
|
71
|
+
// label: 'Yes, using TypeScript syntax',
|
|
72
|
+
// value: 'typescript'
|
|
73
|
+
// },
|
|
74
|
+
// { label: 'No', value: null }
|
|
75
|
+
// ]
|
|
76
|
+
// }),
|
|
77
|
+
|
|
78
|
+
features: () =>
|
|
79
|
+
p.multiselect({
|
|
80
|
+
message: 'Select additional options (use arrow keys/space bar)',
|
|
81
|
+
required: false,
|
|
82
|
+
options: [
|
|
83
|
+
{
|
|
84
|
+
value: 'eslint',
|
|
85
|
+
label: 'Add ESLint for code linting'
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
value: 'prettier',
|
|
89
|
+
label: 'Add Prettier for code formatting'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: 'jest',
|
|
93
|
+
label: 'Add jest for unit testing'
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
{ onCancel: () => process.exit(1) }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await create(cwd, {
|
|
102
|
+
name: path.basename(path.resolve(cwd)),
|
|
103
|
+
template: /** @type {'default' | 'skeleton' | 'skeletonlib'} */ (options.template),
|
|
104
|
+
// types: options.types,
|
|
105
|
+
types: null,
|
|
106
|
+
prettier: options.features.includes('prettier'),
|
|
107
|
+
eslint: options.features.includes('eslint'),
|
|
108
|
+
jest: options.features.includes('jest'),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
p.outro('Your project is ready!');
|
|
112
|
+
|
|
113
|
+
if (options.types === 'typescript') {
|
|
114
|
+
console.log(bold('✔ Typescript'));
|
|
115
|
+
} else if (options.types === 'checkjs') {
|
|
116
|
+
console.log(bold('✔ Type-checked JavaScript'));
|
|
117
|
+
console.log(cyan(' https://www.typescriptlang.org/tsconfig#checkJs\n'));
|
|
118
|
+
} else if (options.template === 'skeletonlib') {
|
|
119
|
+
const warning = yellow('▲');
|
|
120
|
+
console.log(
|
|
121
|
+
`${warning} You chose to not add type checking, but TypeScript will still be installed in order to generate type definitions when building the library\n`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (options.features.includes('eslint')) {
|
|
126
|
+
console.log(bold('✔ ESLint'));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (options.features.includes('prettier')) {
|
|
130
|
+
console.log(bold('✔ Prettier'));
|
|
131
|
+
console.log(cyan(' https://prettier.io/docs/en/options.html'));
|
|
132
|
+
console.log(cyan(' https://github.com/sveltejs/prettier-plugin-svelte#options\n'));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (options.features.includes('jest')) {
|
|
136
|
+
console.log(bold('✔ jest'));
|
|
137
|
+
console.log(cyan(' https://jest.dev\n'));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// @TODO
|
|
141
|
+
// console.log('Install community-maintained integrations:');
|
|
142
|
+
|
|
143
|
+
console.log('\nNext steps:');
|
|
144
|
+
let i = 1;
|
|
145
|
+
|
|
146
|
+
const relative = path.relative(process.cwd(), cwd);
|
|
147
|
+
if (relative !== '') {
|
|
148
|
+
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
console.log(` ${i++}: ${bold(cyan(`${package_manager} install`))}`);
|
|
152
|
+
// prettier-ignore
|
|
153
|
+
console.log(` ${i++}: ${bold(cyan('git init && git add -A && git commit -m "Initial commit"'))} (optional)`);
|
|
154
|
+
console.log(` ${i++}: ${bold(cyan(`${package_manager} run dev -- --open`))}`);
|
|
155
|
+
|
|
156
|
+
// console.log(`\nTo close the dev server, hit ${bold(cyan('Ctrl-C'))}`);
|
|
157
|
+
console.log(`\nStuck? Visit us at ${cyan('https://scout9.dev/chat')}`);
|
package/dist/shared.json
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
{
|
|
4
|
+
"name": "README.md",
|
|
5
|
+
"include": [],
|
|
6
|
+
"exclude": [],
|
|
7
|
+
"contents": "# create-scout9\n\nEverything you need to build a Scout9 project, powered by [`create-scout9`](https://github.com/Scout9Official/scout9-nodejs/tree/main/packages).\n\n## Creating a project\n\nIf you're seeing this, you've probably already done this step. Congrats!\n\n```bash\n# create a new project in the current directory\nnpm create scout9@latest\n\n# create a new project in my-app\nnpm create scout9@latest my-app\n```\n\n## Developing\n\nOnce you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:\n\n```bash\nnpm run dev\n\n# or start the server and open the app in a new browser tab\nnpm run dev -- --open\n```\n\n## Building\n\nTo create a production version of your app:\n\n```bash\nnpm run build\n```\n\nYou can preview the production build with `npm run preview`.\n\n> To deploy your app, you'll need an [API key](https://scout9.com) from your verified account.\n"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"name": ".eslintignore",
|
|
11
|
+
"include": [
|
|
12
|
+
"eslint"
|
|
13
|
+
],
|
|
14
|
+
"exclude": [],
|
|
15
|
+
"contents": ".DS_Store\nnode_modules\n/build\n/.scout9\n/package\n.env\n.env.*\n!.env.example\n\n# Ignore files for PNPM, NPM and YARN\npnpm-lock.yaml\npackage-lock.json\nyarn.lock\n"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "package.json",
|
|
19
|
+
"include": [
|
|
20
|
+
"eslint"
|
|
21
|
+
],
|
|
22
|
+
"exclude": [],
|
|
23
|
+
"contents": "{\n\t\"devDependencies\": {\n\t\t\"eslint\": \"^8.28.0\"\n\t}\n}\n"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": ".babelrc",
|
|
27
|
+
"include": [
|
|
28
|
+
"jest"
|
|
29
|
+
],
|
|
30
|
+
"exclude": [],
|
|
31
|
+
"contents": "{\n \"presets\": [\n [\"@babel/preset-env\", {\"targets\": {\"node\": \"current\"}}]\n ]\n}\n"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "jest.config.js",
|
|
35
|
+
"include": [
|
|
36
|
+
"jest"
|
|
37
|
+
],
|
|
38
|
+
"exclude": [],
|
|
39
|
+
"contents": "export default {\n // other configurations if needed\n};\n"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "package.json",
|
|
43
|
+
"include": [
|
|
44
|
+
"jest"
|
|
45
|
+
],
|
|
46
|
+
"exclude": [],
|
|
47
|
+
"contents": "{\n \"devDependencies\": {\n \"@babel/cli\": \"^7.23.4\",\n \"@babel/core\": \"^7.23.6\",\n \"@babel/preset-env\": \"^7.23.6\",\n \"jest\": \"^29.7.0\"\n },\n \"scripts\": {\n \"test\": \"jest\"\n }\n}\n"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": ".prettierignore",
|
|
51
|
+
"include": [
|
|
52
|
+
"prettier"
|
|
53
|
+
],
|
|
54
|
+
"exclude": [],
|
|
55
|
+
"contents": "# Ignore files for PNPM, NPM and YARN\npnpm-lock.yaml\npackage-lock.json\nyarn.lock\n"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": ".prettierrc",
|
|
59
|
+
"include": [
|
|
60
|
+
"prettier"
|
|
61
|
+
],
|
|
62
|
+
"exclude": [],
|
|
63
|
+
"contents": "{\n\t\"useTabs\": true,\n\t\"singleQuote\": true,\n\t\"trailingComma\": \"none\",\n\t\"printWidth\": 100,\n\t\"plugins\": [],\n\t\"overrides\": [{ \"files\": \"*.scout9\", \"options\": { \"parser\": \"scout9\" } }]\n}\n"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "package.json",
|
|
67
|
+
"include": [
|
|
68
|
+
"prettier"
|
|
69
|
+
],
|
|
70
|
+
"exclude": [],
|
|
71
|
+
"contents": "{\n\t\"devDependencies\": {\n\t\t\"prettier\": \"^3.1.1\"\n\t}\n}\n"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "package.json",
|
|
75
|
+
"include": [
|
|
76
|
+
"typescript"
|
|
77
|
+
],
|
|
78
|
+
"exclude": [],
|
|
79
|
+
"contents": "{\n \"scripts\": {\n \"build\": \"tsc\"\n },\n \"devDependencies\": {\n \"typescript\": \"^5.0.0\",\n \"tslib\": \"^2.4.1\"\n }\n}\n"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "tsconfig.json",
|
|
83
|
+
"include": [
|
|
84
|
+
"typescript"
|
|
85
|
+
],
|
|
86
|
+
"exclude": [],
|
|
87
|
+
"contents": "{\n \"compilerOptions\": {\n \"allowJs\": true,\n \"checkJs\": true,\n \"esModuleInterop\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"resolveJsonModule\": true,\n \"skipLibCheck\": true,\n \"sourceMap\": true,\n \"strict\": true,\n \"moduleResolution\": \"bundler\"\n }\n}\n"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"name": "src/app.test.js",
|
|
91
|
+
"include": [
|
|
92
|
+
"default",
|
|
93
|
+
"jest"
|
|
94
|
+
],
|
|
95
|
+
"exclude": [],
|
|
96
|
+
"contents": "import { createMockWorkflowEvent } from '../platform/src/index.js';\nimport Scout9App from './app.js';\n\ndescribe('Scout9App', () => {\n\n it('Should try to ask customer what type of pizza they want', async () => {\n const event = createMockWorkflowEvent('Hey I would like a pizza', 'pizzaOrder');\n\n // Alternatively you can run the app using sendEvent\n // const response = await sendEvent(event);\n\n const response = await Scout9App(event);\n expect(response.instructions).toEqual('Figure out what pizza sizes, toppings are needed for order');\n });\n\n});\n"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "package.json",
|
|
100
|
+
"include": [
|
|
101
|
+
"eslint",
|
|
102
|
+
"prettier"
|
|
103
|
+
],
|
|
104
|
+
"exclude": [],
|
|
105
|
+
"contents": "{\n\t\"devDependencies\": {\n\t\t\"eslint-config-prettier\": \"^9.1.0\"\n\t},\n\t\"scripts\": {\n\t\t\"lint\": \"prettier --check && eslint .\",\n\t\t\"format\": \"prettier --write \"\n\t}\n}\n"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": ".eslintrc.cjs",
|
|
109
|
+
"include": [
|
|
110
|
+
"eslint",
|
|
111
|
+
"typescript"
|
|
112
|
+
],
|
|
113
|
+
"exclude": [],
|
|
114
|
+
"contents": "/** @type { import(\"eslint\").Linter.FlatConfig } */\nmodule.exports = {\n\troot: true,\n\textends: [\n\t\t'eslint:recommended',\n\t\t'plugin:@typescript-eslint/recommended'\n\t],\n\tparser: '@typescript-eslint/parser',\n\tplugins: ['@typescript-eslint'],\n\tparserOptions: {\n\t\tsourceType: 'module',\n\t\tecmaVersion: 2020,\n\t\textraFileExtensions: ['.scout9']\n\t},\n\tenv: {\n\t\tbrowser: true,\n\t\tes2017: true,\n\t\tnode: true\n\t},\n\t// overrides: [\n\t// \t{\n\t// \t\tfiles: ['*.scout9'],\n\t// \t\tparser: 'scout9-eslint-parser',\n\t// \t\tparserOptions: {\n\t// \t\t\tparser: '@typescript-eslint/parser'\n\t// \t\t}\n\t// \t}\n\t// ]\n};\n"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"name": "package.json",
|
|
118
|
+
"include": [
|
|
119
|
+
"eslint",
|
|
120
|
+
"typescript"
|
|
121
|
+
],
|
|
122
|
+
"exclude": [],
|
|
123
|
+
"contents": "{\n\t\"devDependencies\": {\n\t\t\"@typescript-eslint/eslint-plugin\": \"^6.0.0\",\n\t\t\"@typescript-eslint/parser\": \"^6.0.0\"\n\t}\n}\n"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"name": "package.json",
|
|
127
|
+
"include": [
|
|
128
|
+
"eslint"
|
|
129
|
+
],
|
|
130
|
+
"exclude": [
|
|
131
|
+
"prettier"
|
|
132
|
+
],
|
|
133
|
+
"contents": "{\n\t\"scripts\": {\n\t\t\"lint\": \"eslint \"\n\t}\n}\n"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": ".eslintrc.cjs",
|
|
137
|
+
"include": [
|
|
138
|
+
"eslint"
|
|
139
|
+
],
|
|
140
|
+
"exclude": [
|
|
141
|
+
"typescript"
|
|
142
|
+
],
|
|
143
|
+
"contents": "/** @type { import(\"eslint\").Linter.FlatConfig } */\nmodule.exports = {\n\troot: true,\n\textends: ['eslint:recommended'],\n\tparserOptions: {\n\t\tsourceType: 'module',\n\t\tecmaVersion: 2020,\n\t\textraFileExtensions: ['.scout9']\n\t},\n\tenv: {\n\t\tbrowser: true,\n\t\tes2017: true,\n\t\tnode: true\n\t}\n};\n"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"name": "src/app.test.js",
|
|
147
|
+
"include": [
|
|
148
|
+
"jest",
|
|
149
|
+
"skeleton"
|
|
150
|
+
],
|
|
151
|
+
"exclude": [],
|
|
152
|
+
"contents": "describe('sum test', () => {\n\tit('adds 1 + 2 to equal 3', () => {\n\t\texpect(1 + 2).toBe(3);\n\t});\n});\n"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"name": ".babelrc",
|
|
156
|
+
"include": [
|
|
157
|
+
"typescript",
|
|
158
|
+
"jest"
|
|
159
|
+
],
|
|
160
|
+
"exclude": [],
|
|
161
|
+
"contents": "{\n \"presets\": [\n [\"@babel/preset-env\", {\"targets\": {\"node\": \"current\"}}],\n \"@babel/preset-typescript\"\n ]\n}\n"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"name": "package.json",
|
|
165
|
+
"include": [
|
|
166
|
+
"typescript",
|
|
167
|
+
"jest"
|
|
168
|
+
],
|
|
169
|
+
"exclude": [],
|
|
170
|
+
"contents": "{\n \"scripts\": {\n \"build\": \"tsc\"\n },\n \"devDependencies\": {\n \"@babel/preset-typescript\": \"^7.23.3\",\n \"@types/jest\": \"^29.5.11\"\n }\n}\n"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"name": "package.json",
|
|
174
|
+
"include": [
|
|
175
|
+
"prettier"
|
|
176
|
+
],
|
|
177
|
+
"exclude": [
|
|
178
|
+
"eslint"
|
|
179
|
+
],
|
|
180
|
+
"contents": "{\n\t\"scripts\": {\n\t\t\"lint\": \"prettier --check \",\n\t\t\"format\": \"prettier --write \"\n\t}\n}\n"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"name": ".eslintrc.cjs",
|
|
184
|
+
"include": [
|
|
185
|
+
"eslint",
|
|
186
|
+
"prettier",
|
|
187
|
+
"typescript"
|
|
188
|
+
],
|
|
189
|
+
"exclude": [],
|
|
190
|
+
"contents": "/** @type { import(\"eslint\").Linter.FlatConfig } */\nmodule.exports = {\n\troot: true,\n\textends: [\n\t\t'eslint:recommended',\n\t\t'plugin:@typescript-eslint/recommended',\n\t\t'prettier'\n\t],\n\tparser: '@typescript-eslint/parser',\n\tplugins: ['@typescript-eslint'],\n\tparserOptions: {\n\t\tsourceType: 'module',\n\t\tecmaVersion: 2020,\n\t\textraFileExtensions: ['.scout9']\n\t},\n\tenv: {\n\t\tbrowser: true,\n\t\tes2017: true,\n\t\tnode: true\n\t},\n\t// overrides: [\n\t// \t{\n\t// \t\tfiles: ['*.scout9'],\n\t// \t\tparser: 'scout9-eslint-parser',\n\t// \t\tparserOptions: {\n\t// \t\t\tparser: '@typescript-eslint/parser'\n\t// \t\t}\n\t// \t}\n\t// ]\n};\n"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"name": ".eslintrc.cjs",
|
|
194
|
+
"include": [
|
|
195
|
+
"eslint",
|
|
196
|
+
"prettier"
|
|
197
|
+
],
|
|
198
|
+
"exclude": [
|
|
199
|
+
"typescript"
|
|
200
|
+
],
|
|
201
|
+
"contents": "/** @type { import(\"eslint\").Linter.FlatConfig } */\nmodule.exports = {\n\troot: true,\n\textends: ['eslint:recommended', 'prettier'],\n\tparserOptions: {\n\t\tsourceType: 'module',\n\t\tecmaVersion: 2020,\n\t\textraFileExtensions: ['.scout9']\n\t},\n\tenv: {\n\t\tbrowser: true,\n\t\tes2017: true,\n\t\tnode: true\n\t}\n};\n"
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
engine-strict=true
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "src/app.js",
|
|
4
|
+
"contents": "import { EventResponse } from '@scout9/app';\n\nimport PizzaOrder from './workflows/pizzaOrder/workflow.js';\n\nexport default async function Scout9App(event) {\n\n console.log(EventResponse);\n if (event.intent === 'pizzaOrder') {\n // run pizza order workflow\n return PizzaOrder(event);\n } else {\n if (event.stagnationCount < 2) {\n return {\n instructions: 'Double check if the user is looking to order a pizza'\n }\n } else {\n // End auto replies, forward to agent for manual intervention\n return {\n forward: true,\n }\n }\n }\n\n}\n"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "src/entities/agents/index.js",
|
|
8
|
+
"contents": "/**\n * Required core entity type: Agents represents you and your team\n */\nexport default function Agents() {\n return [\n {\n id: 'agent-1',\n firstName: 'Agent',\n lastName: 'Smith',\n forwardPhone: '+15555555555',\n forwardEmail: '',\n programmablePhoneNumber: '+15555555555',\n }\n ];\n}\n"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "src/entities/customers/[customer]/api.js",
|
|
12
|
+
"contents": "import { json } from '../../../../platform/src/exports.js';\n\n// @TODO replace with your CRM api\nimport { customerMockDb } from '../../../lib/customer-mock-db';\n\n\n/**\n * Get customer info from your CRM\n */\nexport const GET = async ({params}) => {\n return json(await customerMockDb.get(params.customer));\n};\n\n/**\n * When a customer is created on scout9's side\n *\n * Example:\n * A new or unrecognized customer has contacted an agent. Scout9 has captured some preliminary information\n * about them and sent this POST request. Take the information to either add a new customer record to your CRM\n * or return an existing customer id to map the correct customer document.\n */\nexport const POST = async ({params, body: newCustomer}) => {\n // Scout9 will generate random id for new customers, but whatever id you return back will be used for the new customer\n const {id: crmId} = await customerMockDb.add(params.customer, newCustomer);\n return json({success: true, id: crmId}, {status: 200});\n};\n\n/**\n * New customer info revealed, use this to save the customer info to your CRM\n *\n * Example:\n * In a conversation, if any new data is found, Scout9 will send a PUT or PATCH request to allow for you to update\n * your CRM accordingly.\n */\nexport const PUT = async ({params, body: updatedCustomer}) => {\n // const id = params.customer;\n\n console.log('updatedCustomer', updatedCustomer);\n // @TODO REST call to api to save customer info\n\n // @TODO REST call to api to save customer info\n return json({success: true}, {status: 200});\n};\n\n\n/**\n * Customer request to be removed from platform, use this to remove/update the customer info from your CRM\n *\n * Example:\n * A customer has opt-out of text messaging, Scout9 will send a DELETE message for you to remove any data, returning\n * back success: true will then have Scout9 delete any data on their end as well.\n */\nexport const DELETE = async ({params, request}) => {\n await customerMockDb.remove(params.customer);\n return json({success: true}, {status: 200});\n};\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "src/entities/customers/api.js",
|
|
16
|
+
"contents": "import { EventResponse } from '../../../platform/src/index.js';\nimport { customerMockDb } from '../../lib/customer-mock-db.js';\n\n/**\n * Required entity - use this to sync with your CRM\n *\n * Query customer info from your CRM\n */\nexport const QUERY = async ({searchParams}) => {\n const {page, q, orderBy, endAt, startAt, limit} = searchParams;\n const customers = await customerMockDb.query(\n q,\n page ? parseInt(page) : undefined,\n limit ? parseInt(limit) : undefined,\n orderBy ? parseInt(orderBy) : undefined,\n endAt ? parseInt(endAt) : undefined,\n startAt ? parseInt(startAt) : undefined,\n );\n return EventResponse.json(customers, {status: 200});\n};\n"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "src/entities/deliveryMethod/index.js",
|
|
20
|
+
"contents": "// import { EntityRootConfiguration } from '../../../platform/src/runtime/client/entity';\n\n// export type DeliveryMethod = {\n// deliveryMethod: 'pickup' | 'delivery';\n// }\n\n/**\n * Example entity to help us differentiate if a user wants a delivery or pickup order\n */\nexport default function () {\n return {\n definitions: [\n {\n value: 'delivery',\n text: [\n 'delivery',\n 'deliver',\n 'delivered',\n 'dropped off',\n 'drop off',\n ]\n },\n {\n value: 'pickup',\n text: [\n 'pickup',\n 'pick this one up',\n 'pick up',\n ]\n },\n ],\n training:\n [\n ...[\n 'I\\'ll have my order %delivery_method%',\n 'I\\'ll do a %delivery_method% order',\n '%delivery_method% please',\n ].map((text) => ({text, intent: 'delivery_method'})),\n ],\n tests: [\n {\n text: 'drop off order please',\n expected: {\n intent: 'deliveryMethod',\n context: {\n 'deliveryMethod': 'delivery'\n }\n },\n },\n {\n text: 'I\\'ll pick this one up',\n expected: {\n intent: 'deliveryMethod',\n context: {\n 'deliveryMethod': 'pickup'\n }\n },\n }\n ],\n }\n}\n"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "src/entities/pizza/index.js",
|
|
24
|
+
"contents": "/**\n * Example entity that breaks down the pizza the user wants to order\n */\nexport default async function () {\n\n return {\n definitions: [\n {\n utterance: 'quantity',\n value: 'number',\n text: []\n },\n {\n utterance: 'size',\n value: 'small',\n text: ['small', 'sm', '6 inch', '6-inch', '6in', '6 in', '6\"']\n },\n {\n utterance: 'size',\n value: 'medium',\n text: ['medium', 'med', 'md', '8 inch', '8-inch', '8in', '8 in', '8\"']\n },\n {\n utterance: 'size',\n value: 'large',\n text: ['large', 'lg', '12 inch', '12-inch', '12in', '12 in', '12\"']\n },\n {\n utterance: 'size',\n value: 'x-large',\n text: ['extra large', 'x-large', 'xlarge', 'xl', '16 inch', '16-inch', '16in', '16 in', '16\"']\n },\n {\n utterance: 'topping',\n value: 'pepperoni',\n text: ['pepperoni']\n },\n {\n utterance: 'topping',\n value: 'sausage',\n text: ['sausage', 'italian sausage']\n },\n {\n utterance: 'topping',\n value: 'mushroom',\n text: ['mushroom', 'mushrooms', 'mush']\n },\n {\n utterance: 'topping',\n value: 'cheese',\n text: ['cheese', 'cheesy', 'cheez', 'mozarella', 'mozzarella', 'mozz']\n }\n ],\n training: [\n ...[\n '{{quantity:number}} %topping% %size%',\n '{{quantity:number}} %topping% %size%, {{quantity:number}} %topping% %size%, and {{quantity:number}} %topping% %size% and that should be all',\n 'Hey I would like {{quantity:number}} %topping% %size%',\n 'Hey I would like {{quantity:number}} %topping% and %topping%',\n 'Hey I would like {{quantity:number}} %topping%, %topping%, and extra %topping%', // @TODO extra would need to be a separate topping\n 'Hey I would like {{quantity:number}} %size% %topping%, %topping%, and %topping%',\n 'Could I get a %topping% pizza please?',\n 'Could I get {{quantity:number}} %size% %topping%, %topping%, and %topping%?',\n 'Can I order a {{quantity:number}} %size% %topping%, %topping%, and %topping%',\n ].map((text) => ({text, intent: 'pizza'})),\n ...[\n 'Can you remove that %size% %topping% pizza',\n 'Can you remove that %topping% %size% pizza',\n 'Can you cancel that %size% %topping%',\n 'Let\\'s remove that %size% %topping% pizza',\n 'Let\\'s get rid of that %size% %topping%',\n 'Let\\'s remove the %size% %topping% pizza',\n ].map((text) => ({text, intent: 'remove_pizza'})),\n ...[\n 'Can you remove those %topping%?',\n 'Can you remove that %topping%?',\n 'Actually, no %topping%?',\n 'Sorry, I don\\'t want %topping%?',\n ].map((text) => ({text, intent: 'remove_topping'})),\n ...[\n 'Do you have %topping%?',\n ].map((text) => ({text, intent: 'pizza_question'})),\n ],\n tests: [\n {\n text: 'I would like 3 pepperoni medium, 2 cheese medium, and 3 sausage mushroom',\n expected: {\n intent: 'pizza',\n context: {\n pizza: [\n {\n quantity: 3,\n topping: 'pepperoni',\n size: 'medium'\n },\n {\n quantity: 2,\n topping: 'cheese',\n size: 'medium'\n },\n {\n quantity: 3,\n topping: ['sausage', 'mushroom'],\n }\n ]\n },\n },\n },\n {\n text: 'Hey I would like 3 medium pepperoni, sausage, and extra cheese',\n expected: {\n intent: 'pizza',\n context: {\n pizza: [\n {\n quantity: 3,\n topping: ['pepperoni', 'sausage', 'cheese'],\n size: 'medium'\n }\n ]\n }\n }\n }\n ]\n };\n}\n\n"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "src/index.js",
|
|
28
|
+
"contents": "export default {\n\n /**\n * Configure large language model (LLM) settings to generate auto replies\n */\n llm: {\n engine: 'openai',\n model: 'gpt-3.5-turbo',\n },\n /**\n * Configure personal model transformer (PMT) settings to align auto replies the agent's tone\n */\n pmt: {\n engine: 'scout9',\n model: 'orin-2.2'\n },\n}\n"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "src/lib/customer-mock-db.js",
|
|
32
|
+
"contents": "/**\n * This an example adapter for a mock database to your CRM\n */\nexport const customerMockDb = {\n query: async (\n query,\n page,\n limit,\n orderBy,\n endAt,\n startAt,\n ) => Promise.resolve([{id: '1234', name: 'Test Customer', email: '', phone: ''}]),\n get: async (id) => Promise.resolve({id, name: 'Test Customer', email: '', phone: ''}),\n add: async (id, customer) => ({id}),\n update: async (id, updates) => true,\n remove: async (id) => true\n}\n"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "src/lib/drivers.js",
|
|
36
|
+
"contents": "import moment from 'moment';\n\n/**\n * An example service of retrieving an available driver\n */\nexport async function getAvailableDriver(address) {\n // @TODO call driver service to get available driver\n return {\n driver: {\n name: 'Alex'\n },\n deliveryEstimate: moment().add(30, 'minutes')\n }\n}\n"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "src/lib/invoice.js",
|
|
40
|
+
"contents": "/**\n * An example service of creating and retrieving an invoice\n */\nexport async function createInvoice(pizza) {\n // @TODO create invoice\n return {\n id: 'invoice-123',\n subtotal: 6000,\n tax: 600,\n total: 6600,\n invoiceUrl: 'https://example.com/invoice-123'\n };\n}\n\nexport async function getInvoice(id) {\n // @TODO create invoice\n return {\n id: 'invoice-123',\n subtotal: 6000,\n tax: 600,\n total: 6600,\n invoiceUrl: 'https://example.com/invoice-123'\n };\n}\n"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "src/workflows/pizzaOrder/workflow.js",
|
|
44
|
+
"contents": "import moment from 'moment';\nimport { getAvailableDriver } from '../../lib/drivers.js';\nimport { createInvoice, getInvoice } from '../../lib/invoice.js';\n\n/**\n * Example PizzaOrder workflow - this is a simple example of a workflow that can be used to order a pizza\n */\nexport default async function PizzaOrder(\n {\n context,\n customer\n }) {\n\n if (!context.pizza) {\n return {\n instructions: 'Figure out what pizza sizes, toppings are needed for order'\n };\n }\n\n if (!context.deliveryMethod) {\n return {\n instructions: `Determine if ${customer?.firstName || 'the customer'} is doing a delivery or pickup and determine time of pickup/delivery`\n };\n }\n\n if (!context.invoiceId) {\n const invoice = await createInvoice(context.pizza);\n return {\n instructions: `Send invoice to customer`,\n message: `Order created - $${(invoice.total/100).toFixed(2)} you can pay at ${invoice.invoiceUrl}`,\n contextUpsert: {\n invoiceId: invoice.id,\n invoicePaid: false\n }\n }\n }\n\n if (!context.invoicePaid) {\n if (!context.invoiceId) {\n return {forward: true};\n }\n const invoice = await getInvoice(context.invoiceId || '');\n return {\n instructions: `Let user know order is ready for payment at ${invoice.invoiceUrl}`\n }\n }\n\n if (context.deliveryMethod === 'pickup') {\n return [\n {\n instructions: `Let user know their order will be ready at ${moment().add(30, 'minutes').format('h:mm a')}`\n },\n {\n instructions: `Find out if everything was delivered, and let the user know to contact if there are any issues`,\n forward: {\n mode: 'after-reply'\n },\n scheduled: moment().add(30, 'minutes').unix()\n }\n ];\n // @TODO - delay and notify user for feedback and if they got their pizza\n }\n\n if (!context.address && context.deliveryMethod === 'delivery') {\n return {\n instructions: `Ask ${customer.firstName || 'the customer'} for their delivery address`\n };\n }\n\n if (context.address && !context.driver && !context.deliveryTime) {\n const {driver, deliveryEstimate} = await getAvailableDriver(context.address);\n return {\n instructions: `Let ${customer.firstName || 'the customer'} know the pizza order should arrive at ${deliveryEstimate.format(\n 'h:mm a')}`,\n contextUpsert: {\n driver: {\n ...driver\n },\n deliveryTime: deliveryEstimate.unix()\n }\n };\n }\n\n return {\n forward: true\n }\n}\n"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "src/app.js",
|
|
4
|
+
"contents": "import { EventResponse } from '@scout9/app';\n\nimport PizzaOrder from './workflows/pizzaOrder/workflow.js';\n\nexport default async function Scout9App(event) {\n\n console.log(EventResponse);\n if (event.intent === 'pizzaOrder') {\n // run pizza order workflow\n return PizzaOrder(event);\n } else {\n if (event.stagnationCount < 2) {\n return {\n instructions: 'Double check if the user is looking to order a pizza'\n }\n } else {\n // End auto replies, forward to agent for manual intervention\n return {\n forward: true,\n }\n }\n }\n\n}\n"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "src/entities/agents/index.js",
|
|
8
|
+
"contents": "/**\n * Required core entity type: Agents represents you and your team\n */\nexport default function Agents() {\n return [\n {\n id: 'agent-1',\n firstName: 'Agent',\n lastName: 'Smith',\n forwardPhone: '+15555555555',\n forwardEmail: '',\n programmablePhoneNumber: '+15555555555',\n }\n ];\n}\n"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "src/entities/customers/[customer]/api.js",
|
|
12
|
+
"contents": "import { json } from '../../../../platform/src/exports.js';\n\n// @TODO replace with your CRM api\nimport { customerMockDb } from '../../../lib/customer-mock-db';\n\n\n/**\n * Get customer info from your CRM\n */\nexport const GET = async ({params}) => {\n return json(await customerMockDb.get(params.customer));\n};\n\n/**\n * When a customer is created on scout9's side\n *\n * Example:\n * A new or unrecognized customer has contacted an agent. Scout9 has captured some preliminary information\n * about them and sent this POST request. Take the information to either add a new customer record to your CRM\n * or return an existing customer id to map the correct customer document.\n */\nexport const POST = async ({params, body: newCustomer}) => {\n // Scout9 will generate random id for new customers, but whatever id you return back will be used for the new customer\n const {id: crmId} = await customerMockDb.add(params.customer, newCustomer);\n return json({success: true, id: crmId}, {status: 200});\n};\n\n/**\n * New customer info revealed, use this to save the customer info to your CRM\n *\n * Example:\n * In a conversation, if any new data is found, Scout9 will send a PUT or PATCH request to allow for you to update\n * your CRM accordingly.\n */\nexport const PUT = async ({params, body: updatedCustomer}) => {\n // const id = params.customer;\n\n console.log('updatedCustomer', updatedCustomer);\n // @TODO REST call to api to save customer info\n\n // @TODO REST call to api to save customer info\n return json({success: true}, {status: 200});\n};\n\n\n/**\n * Customer request to be removed from platform, use this to remove/update the customer info from your CRM\n *\n * Example:\n * A customer has opt-out of text messaging, Scout9 will send a DELETE message for you to remove any data, returning\n * back success: true will then have Scout9 delete any data on their end as well.\n */\nexport const DELETE = async ({params, request}) => {\n await customerMockDb.remove(params.customer);\n return json({success: true}, {status: 200});\n};\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "src/entities/customers/api.js",
|
|
16
|
+
"contents": "import { EventResponse } from '../../../platform/src/index.js';\nimport { customerMockDb } from '../../lib/customer-mock-db.js';\n\n/**\n * Required entity - use this to sync with your CRM\n *\n * Query customer info from your CRM\n */\nexport const QUERY = async ({searchParams}) => {\n const {page, q, orderBy, endAt, startAt, limit} = searchParams;\n const customers = await customerMockDb.query(\n q,\n page ? parseInt(page) : undefined,\n limit ? parseInt(limit) : undefined,\n orderBy ? parseInt(orderBy) : undefined,\n endAt ? parseInt(endAt) : undefined,\n startAt ? parseInt(startAt) : undefined,\n );\n return EventResponse.json(customers, {status: 200});\n};\n"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "src/entities/deliveryMethod/index.js",
|
|
20
|
+
"contents": "// import { EntityRootConfiguration } from '../../../platform/src/runtime/client/entity';\n\n// export type DeliveryMethod = {\n// deliveryMethod: 'pickup' | 'delivery';\n// }\n\n/**\n * Example entity to help us differentiate if a user wants a delivery or pickup order\n */\nexport default function () {\n return {\n definitions: [\n {\n value: 'delivery',\n text: [\n 'delivery',\n 'deliver',\n 'delivered',\n 'dropped off',\n 'drop off',\n ]\n },\n {\n value: 'pickup',\n text: [\n 'pickup',\n 'pick this one up',\n 'pick up',\n ]\n },\n ],\n training:\n [\n ...[\n 'I\\'ll have my order %delivery_method%',\n 'I\\'ll do a %delivery_method% order',\n '%delivery_method% please',\n ].map((text) => ({text, intent: 'delivery_method'})),\n ],\n tests: [\n {\n text: 'drop off order please',\n expected: {\n intent: 'deliveryMethod',\n context: {\n 'deliveryMethod': 'delivery'\n }\n },\n },\n {\n text: 'I\\'ll pick this one up',\n expected: {\n intent: 'deliveryMethod',\n context: {\n 'deliveryMethod': 'pickup'\n }\n },\n }\n ],\n }\n}\n"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "src/entities/pizza/index.js",
|
|
24
|
+
"contents": "/**\n * Example entity that breaks down the pizza the user wants to order\n */\nexport default async function () {\n\n return {\n definitions: [\n {\n utterance: 'quantity',\n value: 'number',\n text: []\n },\n {\n utterance: 'size',\n value: 'small',\n text: ['small', 'sm', '6 inch', '6-inch', '6in', '6 in', '6\"']\n },\n {\n utterance: 'size',\n value: 'medium',\n text: ['medium', 'med', 'md', '8 inch', '8-inch', '8in', '8 in', '8\"']\n },\n {\n utterance: 'size',\n value: 'large',\n text: ['large', 'lg', '12 inch', '12-inch', '12in', '12 in', '12\"']\n },\n {\n utterance: 'size',\n value: 'x-large',\n text: ['extra large', 'x-large', 'xlarge', 'xl', '16 inch', '16-inch', '16in', '16 in', '16\"']\n },\n {\n utterance: 'topping',\n value: 'pepperoni',\n text: ['pepperoni']\n },\n {\n utterance: 'topping',\n value: 'sausage',\n text: ['sausage', 'italian sausage']\n },\n {\n utterance: 'topping',\n value: 'mushroom',\n text: ['mushroom', 'mushrooms', 'mush']\n },\n {\n utterance: 'topping',\n value: 'cheese',\n text: ['cheese', 'cheesy', 'cheez', 'mozarella', 'mozzarella', 'mozz']\n }\n ],\n training: [\n ...[\n '{{quantity:number}} %topping% %size%',\n '{{quantity:number}} %topping% %size%, {{quantity:number}} %topping% %size%, and {{quantity:number}} %topping% %size% and that should be all',\n 'Hey I would like {{quantity:number}} %topping% %size%',\n 'Hey I would like {{quantity:number}} %topping% and %topping%',\n 'Hey I would like {{quantity:number}} %topping%, %topping%, and extra %topping%', // @TODO extra would need to be a separate topping\n 'Hey I would like {{quantity:number}} %size% %topping%, %topping%, and %topping%',\n 'Could I get a %topping% pizza please?',\n 'Could I get {{quantity:number}} %size% %topping%, %topping%, and %topping%?',\n 'Can I order a {{quantity:number}} %size% %topping%, %topping%, and %topping%',\n ].map((text) => ({text, intent: 'pizza'})),\n ...[\n 'Can you remove that %size% %topping% pizza',\n 'Can you remove that %topping% %size% pizza',\n 'Can you cancel that %size% %topping%',\n 'Let\\'s remove that %size% %topping% pizza',\n 'Let\\'s get rid of that %size% %topping%',\n 'Let\\'s remove the %size% %topping% pizza',\n ].map((text) => ({text, intent: 'remove_pizza'})),\n ...[\n 'Can you remove those %topping%?',\n 'Can you remove that %topping%?',\n 'Actually, no %topping%?',\n 'Sorry, I don\\'t want %topping%?',\n ].map((text) => ({text, intent: 'remove_topping'})),\n ...[\n 'Do you have %topping%?',\n ].map((text) => ({text, intent: 'pizza_question'})),\n ],\n tests: [\n {\n text: 'I would like 3 pepperoni medium, 2 cheese medium, and 3 sausage mushroom',\n expected: {\n intent: 'pizza',\n context: {\n pizza: [\n {\n quantity: 3,\n topping: 'pepperoni',\n size: 'medium'\n },\n {\n quantity: 2,\n topping: 'cheese',\n size: 'medium'\n },\n {\n quantity: 3,\n topping: ['sausage', 'mushroom'],\n }\n ]\n },\n },\n },\n {\n text: 'Hey I would like 3 medium pepperoni, sausage, and extra cheese',\n expected: {\n intent: 'pizza',\n context: {\n pizza: [\n {\n quantity: 3,\n topping: ['pepperoni', 'sausage', 'cheese'],\n size: 'medium'\n }\n ]\n }\n }\n }\n ]\n };\n}\n\n"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "src/index.js",
|
|
28
|
+
"contents": "export default {\n\n /**\n * Configure large language model (LLM) settings to generate auto replies\n */\n llm: {\n engine: 'openai',\n model: 'gpt-3.5-turbo',\n },\n /**\n * Configure personal model transformer (PMT) settings to align auto replies the agent's tone\n */\n pmt: {\n engine: 'scout9',\n model: 'orin-2.2'\n },\n}\n"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "src/lib/customer-mock-db.js",
|
|
32
|
+
"contents": "/**\n * This an example adapter for a mock database to your CRM\n */\nexport const customerMockDb = {\n query: async (\n query,\n page,\n limit,\n orderBy,\n endAt,\n startAt,\n ) => Promise.resolve([{id: '1234', name: 'Test Customer', email: '', phone: ''}]),\n get: async (id) => Promise.resolve({id, name: 'Test Customer', email: '', phone: ''}),\n add: async (id, customer) => ({id}),\n update: async (id, updates) => true,\n remove: async (id) => true\n}\n"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "src/lib/drivers.js",
|
|
36
|
+
"contents": "import moment from 'moment';\n\n/**\n * An example service of retrieving an available driver\n */\nexport async function getAvailableDriver(address) {\n // @TODO call driver service to get available driver\n return {\n driver: {\n name: 'Alex'\n },\n deliveryEstimate: moment().add(30, 'minutes')\n }\n}\n"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "src/lib/invoice.js",
|
|
40
|
+
"contents": "/**\n * An example service of creating and retrieving an invoice\n */\nexport async function createInvoice(pizza) {\n // @TODO create invoice\n return {\n id: 'invoice-123',\n subtotal: 6000,\n tax: 600,\n total: 6600,\n invoiceUrl: 'https://example.com/invoice-123'\n };\n}\n\nexport async function getInvoice(id) {\n // @TODO create invoice\n return {\n id: 'invoice-123',\n subtotal: 6000,\n tax: 600,\n total: 6600,\n invoiceUrl: 'https://example.com/invoice-123'\n };\n}\n"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "src/workflows/pizzaOrder/workflow.js",
|
|
44
|
+
"contents": "import moment from 'moment';\nimport { getAvailableDriver } from '../../lib/drivers.js';\nimport { createInvoice, getInvoice } from '../../lib/invoice.js';\n\n/**\n * Example PizzaOrder workflow - this is a simple example of a workflow that can be used to order a pizza\n */\nexport default async function PizzaOrder(\n {\n context,\n customer\n }) {\n\n if (!context.pizza) {\n return {\n instructions: 'Figure out what pizza sizes, toppings are needed for order'\n };\n }\n\n if (!context.deliveryMethod) {\n return {\n instructions: `Determine if ${customer?.firstName || 'the customer'} is doing a delivery or pickup and determine time of pickup/delivery`\n };\n }\n\n if (!context.invoiceId) {\n const invoice = await createInvoice(context.pizza);\n return {\n instructions: `Send invoice to customer`,\n message: `Order created - $${(invoice.total/100).toFixed(2)} you can pay at ${invoice.invoiceUrl}`,\n contextUpsert: {\n invoiceId: invoice.id,\n invoicePaid: false\n }\n }\n }\n\n if (!context.invoicePaid) {\n if (!context.invoiceId) {\n return {forward: true};\n }\n const invoice = await getInvoice(context.invoiceId || '');\n return {\n instructions: `Let user know order is ready for payment at ${invoice.invoiceUrl}`\n }\n }\n\n if (context.deliveryMethod === 'pickup') {\n return [\n {\n instructions: `Let user know their order will be ready at ${moment().add(30, 'minutes').format('h:mm a')}`\n },\n {\n instructions: `Find out if everything was delivered, and let the user know to contact if there are any issues`,\n forward: {\n mode: 'after-reply'\n },\n scheduled: moment().add(30, 'minutes').unix()\n }\n ];\n // @TODO - delay and notify user for feedback and if they got their pizza\n }\n\n if (!context.address && context.deliveryMethod === 'delivery') {\n return {\n instructions: `Ask ${customer.firstName || 'the customer'} for their delivery address`\n };\n }\n\n if (context.address && !context.driver && !context.deliveryTime) {\n const {driver, deliveryEstimate} = await getAvailableDriver(context.address);\n return {\n instructions: `Let ${customer.firstName || 'the customer'} know the pizza order should arrive at ${deliveryEstimate.format(\n 'h:mm a')}`,\n contextUpsert: {\n driver: {\n ...driver\n },\n deliveryTime: deliveryEstimate.unix()\n }\n };\n }\n\n return {\n forward: true\n }\n}\n"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "src/app.js",
|
|
4
|
+
"contents": "import { EventResponse } from '@scout9/app';\n\nimport PizzaOrder from './workflows/pizzaOrder/workflow.js';\n\nexport default async function Scout9App(event) {\n\n console.log(EventResponse);\n if (event.intent === 'pizzaOrder') {\n // run pizza order workflow\n return PizzaOrder(event);\n } else {\n if (event.stagnationCount < 2) {\n return {\n instructions: 'Double check if the user is looking to order a pizza'\n }\n } else {\n // End auto replies, forward to agent for manual intervention\n return {\n forward: true,\n }\n }\n }\n\n}\n"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "src/entities/agents/index.js",
|
|
8
|
+
"contents": "/**\n * Required core entity type: Agents represents you and your team\n */\nexport default function Agents() {\n return [\n {\n id: 'agent-1',\n firstName: 'Agent',\n lastName: 'Smith',\n forwardPhone: '+15555555555',\n forwardEmail: '',\n programmablePhoneNumber: '+15555555555',\n }\n ];\n}\n"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "src/entities/customers/[customer]/api.js",
|
|
12
|
+
"contents": "import { json } from '../../../../platform/src/exports.js';\n\n// @TODO replace with your CRM api\nimport { customerMockDb } from '../../../lib/customer-mock-db';\n\n\n/**\n * Get customer info from your CRM\n */\nexport const GET = async ({params}) => {\n return json(await customerMockDb.get(params.customer));\n};\n\n/**\n * When a customer is created on scout9's side\n *\n * Example:\n * A new or unrecognized customer has contacted an agent. Scout9 has captured some preliminary information\n * about them and sent this POST request. Take the information to either add a new customer record to your CRM\n * or return an existing customer id to map the correct customer document.\n */\nexport const POST = async ({params, body: newCustomer}) => {\n // Scout9 will generate random id for new customers, but whatever id you return back will be used for the new customer\n const {id: crmId} = await customerMockDb.add(params.customer, newCustomer);\n return json({success: true, id: crmId}, {status: 200});\n};\n\n/**\n * New customer info revealed, use this to save the customer info to your CRM\n *\n * Example:\n * In a conversation, if any new data is found, Scout9 will send a PUT or PATCH request to allow for you to update\n * your CRM accordingly.\n */\nexport const PUT = async ({params, body: updatedCustomer}) => {\n // const id = params.customer;\n\n console.log('updatedCustomer', updatedCustomer);\n // @TODO REST call to api to save customer info\n\n // @TODO REST call to api to save customer info\n return json({success: true}, {status: 200});\n};\n\n\n/**\n * Customer request to be removed from platform, use this to remove/update the customer info from your CRM\n *\n * Example:\n * A customer has opt-out of text messaging, Scout9 will send a DELETE message for you to remove any data, returning\n * back success: true will then have Scout9 delete any data on their end as well.\n */\nexport const DELETE = async ({params, request}) => {\n await customerMockDb.remove(params.customer);\n return json({success: true}, {status: 200});\n};\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "src/entities/customers/api.js",
|
|
16
|
+
"contents": "import { EventResponse } from '../../../platform/src/index.js';\nimport { customerMockDb } from '../../lib/customer-mock-db.js';\n\n/**\n * Required entity - use this to sync with your CRM\n *\n * Query customer info from your CRM\n */\nexport const QUERY = async ({searchParams}) => {\n const {page, q, orderBy, endAt, startAt, limit} = searchParams;\n const customers = await customerMockDb.query(\n q,\n page ? parseInt(page) : undefined,\n limit ? parseInt(limit) : undefined,\n orderBy ? parseInt(orderBy) : undefined,\n endAt ? parseInt(endAt) : undefined,\n startAt ? parseInt(startAt) : undefined,\n );\n return EventResponse.json(customers, {status: 200});\n};\n"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "src/entities/deliveryMethod/index.js",
|
|
20
|
+
"contents": "// import { EntityRootConfiguration } from '../../../platform/src/runtime/client/entity';\n\n// export type DeliveryMethod = {\n// deliveryMethod: 'pickup' | 'delivery';\n// }\n\n/**\n * Example entity to help us differentiate if a user wants a delivery or pickup order\n */\nexport default function () {\n return {\n definitions: [\n {\n value: 'delivery',\n text: [\n 'delivery',\n 'deliver',\n 'delivered',\n 'dropped off',\n 'drop off',\n ]\n },\n {\n value: 'pickup',\n text: [\n 'pickup',\n 'pick this one up',\n 'pick up',\n ]\n },\n ],\n training:\n [\n ...[\n 'I\\'ll have my order %delivery_method%',\n 'I\\'ll do a %delivery_method% order',\n '%delivery_method% please',\n ].map((text) => ({text, intent: 'delivery_method'})),\n ],\n tests: [\n {\n text: 'drop off order please',\n expected: {\n intent: 'deliveryMethod',\n context: {\n 'deliveryMethod': 'delivery'\n }\n },\n },\n {\n text: 'I\\'ll pick this one up',\n expected: {\n intent: 'deliveryMethod',\n context: {\n 'deliveryMethod': 'pickup'\n }\n },\n }\n ],\n }\n}\n"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "src/entities/pizza/index.js",
|
|
24
|
+
"contents": "/**\n * Example entity that breaks down the pizza the user wants to order\n */\nexport default async function () {\n\n return {\n definitions: [\n {\n utterance: 'quantity',\n value: 'number',\n text: []\n },\n {\n utterance: 'size',\n value: 'small',\n text: ['small', 'sm', '6 inch', '6-inch', '6in', '6 in', '6\"']\n },\n {\n utterance: 'size',\n value: 'medium',\n text: ['medium', 'med', 'md', '8 inch', '8-inch', '8in', '8 in', '8\"']\n },\n {\n utterance: 'size',\n value: 'large',\n text: ['large', 'lg', '12 inch', '12-inch', '12in', '12 in', '12\"']\n },\n {\n utterance: 'size',\n value: 'x-large',\n text: ['extra large', 'x-large', 'xlarge', 'xl', '16 inch', '16-inch', '16in', '16 in', '16\"']\n },\n {\n utterance: 'topping',\n value: 'pepperoni',\n text: ['pepperoni']\n },\n {\n utterance: 'topping',\n value: 'sausage',\n text: ['sausage', 'italian sausage']\n },\n {\n utterance: 'topping',\n value: 'mushroom',\n text: ['mushroom', 'mushrooms', 'mush']\n },\n {\n utterance: 'topping',\n value: 'cheese',\n text: ['cheese', 'cheesy', 'cheez', 'mozarella', 'mozzarella', 'mozz']\n }\n ],\n training: [\n ...[\n '{{quantity:number}} %topping% %size%',\n '{{quantity:number}} %topping% %size%, {{quantity:number}} %topping% %size%, and {{quantity:number}} %topping% %size% and that should be all',\n 'Hey I would like {{quantity:number}} %topping% %size%',\n 'Hey I would like {{quantity:number}} %topping% and %topping%',\n 'Hey I would like {{quantity:number}} %topping%, %topping%, and extra %topping%', // @TODO extra would need to be a separate topping\n 'Hey I would like {{quantity:number}} %size% %topping%, %topping%, and %topping%',\n 'Could I get a %topping% pizza please?',\n 'Could I get {{quantity:number}} %size% %topping%, %topping%, and %topping%?',\n 'Can I order a {{quantity:number}} %size% %topping%, %topping%, and %topping%',\n ].map((text) => ({text, intent: 'pizza'})),\n ...[\n 'Can you remove that %size% %topping% pizza',\n 'Can you remove that %topping% %size% pizza',\n 'Can you cancel that %size% %topping%',\n 'Let\\'s remove that %size% %topping% pizza',\n 'Let\\'s get rid of that %size% %topping%',\n 'Let\\'s remove the %size% %topping% pizza',\n ].map((text) => ({text, intent: 'remove_pizza'})),\n ...[\n 'Can you remove those %topping%?',\n 'Can you remove that %topping%?',\n 'Actually, no %topping%?',\n 'Sorry, I don\\'t want %topping%?',\n ].map((text) => ({text, intent: 'remove_topping'})),\n ...[\n 'Do you have %topping%?',\n ].map((text) => ({text, intent: 'pizza_question'})),\n ],\n tests: [\n {\n text: 'I would like 3 pepperoni medium, 2 cheese medium, and 3 sausage mushroom',\n expected: {\n intent: 'pizza',\n context: {\n pizza: [\n {\n quantity: 3,\n topping: 'pepperoni',\n size: 'medium'\n },\n {\n quantity: 2,\n topping: 'cheese',\n size: 'medium'\n },\n {\n quantity: 3,\n topping: ['sausage', 'mushroom'],\n }\n ]\n },\n },\n },\n {\n text: 'Hey I would like 3 medium pepperoni, sausage, and extra cheese',\n expected: {\n intent: 'pizza',\n context: {\n pizza: [\n {\n quantity: 3,\n topping: ['pepperoni', 'sausage', 'cheese'],\n size: 'medium'\n }\n ]\n }\n }\n }\n ]\n };\n}\n\n"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "src/index.js",
|
|
28
|
+
"contents": "export default {\n\n /**\n * Configure large language model (LLM) settings to generate auto replies\n */\n llm: {\n engine: 'openai',\n model: 'gpt-3.5-turbo',\n },\n /**\n * Configure personal model transformer (PMT) settings to align auto replies the agent's tone\n */\n pmt: {\n engine: 'scout9',\n model: 'orin-2.2'\n },\n}\n"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "src/lib/customer-mock-db.js",
|
|
32
|
+
"contents": "/**\n * This an example adapter for a mock database to your CRM\n */\nexport const customerMockDb = {\n query: async (\n query,\n page,\n limit,\n orderBy,\n endAt,\n startAt,\n ) => Promise.resolve([{id: '1234', name: 'Test Customer', email: '', phone: ''}]),\n get: async (id) => Promise.resolve({id, name: 'Test Customer', email: '', phone: ''}),\n add: async (id, customer) => ({id}),\n update: async (id, updates) => true,\n remove: async (id) => true\n}\n"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "src/lib/drivers.js",
|
|
36
|
+
"contents": "import moment from 'moment';\n\n/**\n * An example service of retrieving an available driver\n */\nexport async function getAvailableDriver(address) {\n // @TODO call driver service to get available driver\n return {\n driver: {\n name: 'Alex'\n },\n deliveryEstimate: moment().add(30, 'minutes')\n }\n}\n"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "src/lib/invoice.js",
|
|
40
|
+
"contents": "/**\n * An example service of creating and retrieving an invoice\n */\nexport async function createInvoice(pizza) {\n // @TODO create invoice\n return {\n id: 'invoice-123',\n subtotal: 6000,\n tax: 600,\n total: 6600,\n invoiceUrl: 'https://example.com/invoice-123'\n };\n}\n\nexport async function getInvoice(id) {\n // @TODO create invoice\n return {\n id: 'invoice-123',\n subtotal: 6000,\n tax: 600,\n total: 6600,\n invoiceUrl: 'https://example.com/invoice-123'\n };\n}\n"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": "src/workflows/pizzaOrder/workflow.js",
|
|
44
|
+
"contents": "import moment from 'moment';\nimport { getAvailableDriver } from '../../lib/drivers.js';\nimport { createInvoice, getInvoice } from '../../lib/invoice.js';\n\n/**\n * Example PizzaOrder workflow - this is a simple example of a workflow that can be used to order a pizza\n */\nexport default async function PizzaOrder(\n {\n context,\n customer\n }) {\n\n if (!context.pizza) {\n return {\n instructions: 'Figure out what pizza sizes, toppings are needed for order'\n };\n }\n\n if (!context.deliveryMethod) {\n return {\n instructions: `Determine if ${customer?.firstName || 'the customer'} is doing a delivery or pickup and determine time of pickup/delivery`\n };\n }\n\n if (!context.invoiceId) {\n const invoice = await createInvoice(context.pizza);\n return {\n instructions: `Send invoice to customer`,\n message: `Order created - $${(invoice.total/100).toFixed(2)} you can pay at ${invoice.invoiceUrl}`,\n contextUpsert: {\n invoiceId: invoice.id,\n invoicePaid: false\n }\n }\n }\n\n if (!context.invoicePaid) {\n if (!context.invoiceId) {\n return {forward: true};\n }\n const invoice = await getInvoice(context.invoiceId || '');\n return {\n instructions: `Let user know order is ready for payment at ${invoice.invoiceUrl}`\n }\n }\n\n if (context.deliveryMethod === 'pickup') {\n return [\n {\n instructions: `Let user know their order will be ready at ${moment().add(30, 'minutes').format('h:mm a')}`\n },\n {\n instructions: `Find out if everything was delivered, and let the user know to contact if there are any issues`,\n forward: {\n mode: 'after-reply'\n },\n scheduled: moment().add(30, 'minutes').unix()\n }\n ];\n // @TODO - delay and notify user for feedback and if they got their pizza\n }\n\n if (!context.address && context.deliveryMethod === 'delivery') {\n return {\n instructions: `Ask ${customer.firstName || 'the customer'} for their delivery address`\n };\n }\n\n if (context.address && !context.driver && !context.deliveryTime) {\n const {driver, deliveryEstimate} = await getAvailableDriver(context.address);\n return {\n instructions: `Let ${customer.firstName || 'the customer'} know the pizza order should arrive at ${deliveryEstimate.format(\n 'h:mm a')}`,\n contextUpsert: {\n driver: {\n ...driver\n },\n deliveryTime: deliveryEstimate.unix()\n }\n };\n }\n\n return {\n forward: true\n }\n}\n"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
engine-strict=true
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "src/app.js",
|
|
4
|
+
"contents": "import DefaultWorkflow from './workflows/default/workflow.js';\n\nexport default async function Scout9App(event) {\n return DefaultWorkflow(event);\n}\n"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "src/entities/agents/index.js",
|
|
8
|
+
"contents": "/**\n * Required core entity type: Agents represents you and your team\n */\nexport default function Agents() {\n return [\n {\n id: 'agent-1',\n firstName: 'Agent',\n lastName: 'Smith',\n forwardPhone: '+15555555555',\n forwardEmail: '',\n programmablePhoneNumber: '+15555555555',\n }\n ];\n}\n"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "src/entities/customers/[customer]/api.js",
|
|
12
|
+
"contents": "import { json } from '../../../../platform/src/exports.js';\n\n// @TODO replace with your CRM api\nimport { customerMockDb } from '../../../lib/customer-mock-db';\n\n\n/**\n * Get customer info from your CRM\n */\nexport const GET = async ({params}) => {\n return json(await customerMockDb.get(params.customer));\n};\n\n/**\n * When a customer is created on scout9's side\n *\n * Example:\n * A new or unrecognized customer has contacted an agent. Scout9 has captured some preliminary information\n * about them and sent this POST request. Take the information to either add a new customer record to your CRM\n * or return an existing customer id to map the correct customer document.\n */\nexport const POST = async ({params, body: newCustomer}) => {\n // Scout9 will generate random id for new customers, but whatever id you return back will be used for the new customer\n const {id: crmId} = await customerMockDb.add(params.customer, newCustomer);\n return json({success: true, id: crmId}, {status: 200});\n};\n\n/**\n * New customer info revealed, use this to save the customer info to your CRM\n *\n * Example:\n * In a conversation, if any new data is found, Scout9 will send a PUT or PATCH request to allow for you to update\n * your CRM accordingly.\n */\nexport const PUT = async ({params, body: updatedCustomer}) => {\n // const id = params.customer;\n\n console.log('updatedCustomer', updatedCustomer);\n // @TODO REST call to api to save customer info\n\n // @TODO REST call to api to save customer info\n return json({success: true}, {status: 200});\n};\n\n\n/**\n * Customer request to be removed from platform, use this to remove/update the customer info from your CRM\n *\n * Example:\n * A customer has opt-out of text messaging, Scout9 will send a DELETE message for you to remove any data, returning\n * back success: true will then have Scout9 delete any data on their end as well.\n */\nexport const DELETE = async ({params, request}) => {\n await customerMockDb.remove(params.customer);\n return json({success: true}, {status: 200});\n};\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "src/entities/customers/api.js",
|
|
16
|
+
"contents": "import { EventResponse } from '../../../platform/src/index.js';\nimport { customerMockDb } from '../../lib/customer-mock-db.js';\n\n/**\n * Required entity - use this to sync with your CRM\n *\n * Query customer info from your CRM\n */\nexport const QUERY = async ({searchParams}) => {\n const {page, q, orderBy, endAt, startAt, limit} = searchParams;\n const customers = await customerMockDb.query(\n q,\n page ? parseInt(page) : undefined,\n limit ? parseInt(limit) : undefined,\n orderBy ? parseInt(orderBy) : undefined,\n endAt ? parseInt(endAt) : undefined,\n startAt ? parseInt(startAt) : undefined,\n );\n return EventResponse.json(customers, {status: 200});\n};\n"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "src/lib/customer-mock-db.js",
|
|
20
|
+
"contents": "/**\n * This an example adapter for a mock database to your CRM\n */\nexport const customerMockDb = {\n query: async (\n query,\n page,\n limit,\n orderBy,\n endAt,\n startAt,\n ) => Promise.resolve([{id: '1234', name: 'Test Customer', email: '', phone: ''}]),\n get: async (id) => Promise.resolve({id, name: 'Test Customer', email: '', phone: ''}),\n add: async (id, customer) => ({id}),\n update: async (id, updates) => true,\n remove: async (id) => true\n}\n"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "src/workflows/default/workflow.js",
|
|
24
|
+
"contents": "export default async function DefaultWorkflow(\n {\n context,\n customer\n }) {\n return {\n forward: true,\n };\n}\n"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "src/app.js",
|
|
4
|
+
"contents": "import DefaultWorkflow from './workflows/default/workflow.js';\n\nexport default async function Scout9App(event) {\n return DefaultWorkflow(event);\n}\n"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "src/entities/agents/index.js",
|
|
8
|
+
"contents": "/**\n * Required core entity type: Agents represents you and your team\n */\nexport default function Agents() {\n return [\n {\n id: 'agent-1',\n firstName: 'Agent',\n lastName: 'Smith',\n forwardPhone: '+15555555555',\n forwardEmail: '',\n programmablePhoneNumber: '+15555555555',\n }\n ];\n}\n"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "src/entities/customers/[customer]/api.js",
|
|
12
|
+
"contents": "import { json } from '../../../../platform/src/exports.js';\n\n// @TODO replace with your CRM api\nimport { customerMockDb } from '../../../lib/customer-mock-db';\n\n\n/**\n * Get customer info from your CRM\n */\nexport const GET = async ({params}) => {\n return json(await customerMockDb.get(params.customer));\n};\n\n/**\n * When a customer is created on scout9's side\n *\n * Example:\n * A new or unrecognized customer has contacted an agent. Scout9 has captured some preliminary information\n * about them and sent this POST request. Take the information to either add a new customer record to your CRM\n * or return an existing customer id to map the correct customer document.\n */\nexport const POST = async ({params, body: newCustomer}) => {\n // Scout9 will generate random id for new customers, but whatever id you return back will be used for the new customer\n const {id: crmId} = await customerMockDb.add(params.customer, newCustomer);\n return json({success: true, id: crmId}, {status: 200});\n};\n\n/**\n * New customer info revealed, use this to save the customer info to your CRM\n *\n * Example:\n * In a conversation, if any new data is found, Scout9 will send a PUT or PATCH request to allow for you to update\n * your CRM accordingly.\n */\nexport const PUT = async ({params, body: updatedCustomer}) => {\n // const id = params.customer;\n\n console.log('updatedCustomer', updatedCustomer);\n // @TODO REST call to api to save customer info\n\n // @TODO REST call to api to save customer info\n return json({success: true}, {status: 200});\n};\n\n\n/**\n * Customer request to be removed from platform, use this to remove/update the customer info from your CRM\n *\n * Example:\n * A customer has opt-out of text messaging, Scout9 will send a DELETE message for you to remove any data, returning\n * back success: true will then have Scout9 delete any data on their end as well.\n */\nexport const DELETE = async ({params, request}) => {\n await customerMockDb.remove(params.customer);\n return json({success: true}, {status: 200});\n};\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "src/entities/customers/api.js",
|
|
16
|
+
"contents": "import { EventResponse } from '../../../platform/src/index.js';\nimport { customerMockDb } from '../../lib/customer-mock-db.js';\n\n/**\n * Required entity - use this to sync with your CRM\n *\n * Query customer info from your CRM\n */\nexport const QUERY = async ({searchParams}) => {\n const {page, q, orderBy, endAt, startAt, limit} = searchParams;\n const customers = await customerMockDb.query(\n q,\n page ? parseInt(page) : undefined,\n limit ? parseInt(limit) : undefined,\n orderBy ? parseInt(orderBy) : undefined,\n endAt ? parseInt(endAt) : undefined,\n startAt ? parseInt(startAt) : undefined,\n );\n return EventResponse.json(customers, {status: 200});\n};\n"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "src/lib/customer-mock-db.js",
|
|
20
|
+
"contents": "/**\n * This an example adapter for a mock database to your CRM\n */\nexport const customerMockDb = {\n query: async (\n query,\n page,\n limit,\n orderBy,\n endAt,\n startAt,\n ) => Promise.resolve([{id: '1234', name: 'Test Customer', email: '', phone: ''}]),\n get: async (id) => Promise.resolve({id, name: 'Test Customer', email: '', phone: ''}),\n add: async (id, customer) => ({id}),\n update: async (id, updates) => true,\n remove: async (id) => true\n}\n"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "src/workflows/default/workflow.js",
|
|
24
|
+
"contents": "export default async function DefaultWorkflow(\n {\n context,\n customer\n }) {\n return {\n forward: true,\n };\n}\n"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "src/app.js",
|
|
4
|
+
"contents": "import DefaultWorkflow from './workflows/default/workflow.js';\n\nexport default async function Scout9App(event) {\n return DefaultWorkflow(event);\n}\n"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"name": "src/entities/agents/index.js",
|
|
8
|
+
"contents": "/**\n * Required core entity type: Agents represents you and your team\n */\nexport default function Agents() {\n return [\n {\n id: 'agent-1',\n firstName: 'Agent',\n lastName: 'Smith',\n forwardPhone: '+15555555555',\n forwardEmail: '',\n programmablePhoneNumber: '+15555555555',\n }\n ];\n}\n"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "src/entities/customers/[customer]/api.js",
|
|
12
|
+
"contents": "import { json } from '../../../../platform/src/exports.js';\n\n// @TODO replace with your CRM api\nimport { customerMockDb } from '../../../lib/customer-mock-db';\n\n\n/**\n * Get customer info from your CRM\n */\nexport const GET = async ({params}) => {\n return json(await customerMockDb.get(params.customer));\n};\n\n/**\n * When a customer is created on scout9's side\n *\n * Example:\n * A new or unrecognized customer has contacted an agent. Scout9 has captured some preliminary information\n * about them and sent this POST request. Take the information to either add a new customer record to your CRM\n * or return an existing customer id to map the correct customer document.\n */\nexport const POST = async ({params, body: newCustomer}) => {\n // Scout9 will generate random id for new customers, but whatever id you return back will be used for the new customer\n const {id: crmId} = await customerMockDb.add(params.customer, newCustomer);\n return json({success: true, id: crmId}, {status: 200});\n};\n\n/**\n * New customer info revealed, use this to save the customer info to your CRM\n *\n * Example:\n * In a conversation, if any new data is found, Scout9 will send a PUT or PATCH request to allow for you to update\n * your CRM accordingly.\n */\nexport const PUT = async ({params, body: updatedCustomer}) => {\n // const id = params.customer;\n\n console.log('updatedCustomer', updatedCustomer);\n // @TODO REST call to api to save customer info\n\n // @TODO REST call to api to save customer info\n return json({success: true}, {status: 200});\n};\n\n\n/**\n * Customer request to be removed from platform, use this to remove/update the customer info from your CRM\n *\n * Example:\n * A customer has opt-out of text messaging, Scout9 will send a DELETE message for you to remove any data, returning\n * back success: true will then have Scout9 delete any data on their end as well.\n */\nexport const DELETE = async ({params, request}) => {\n await customerMockDb.remove(params.customer);\n return json({success: true}, {status: 200});\n};\n"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "src/entities/customers/api.js",
|
|
16
|
+
"contents": "import { EventResponse } from '../../../platform/src/index.js';\nimport { customerMockDb } from '../../lib/customer-mock-db.js';\n\n/**\n * Required entity - use this to sync with your CRM\n *\n * Query customer info from your CRM\n */\nexport const QUERY = async ({searchParams}) => {\n const {page, q, orderBy, endAt, startAt, limit} = searchParams;\n const customers = await customerMockDb.query(\n q,\n page ? parseInt(page) : undefined,\n limit ? parseInt(limit) : undefined,\n orderBy ? parseInt(orderBy) : undefined,\n endAt ? parseInt(endAt) : undefined,\n startAt ? parseInt(startAt) : undefined,\n );\n return EventResponse.json(customers, {status: 200});\n};\n"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "src/lib/customer-mock-db.js",
|
|
20
|
+
"contents": "/**\n * This an example adapter for a mock database to your CRM\n */\nexport const customerMockDb = {\n query: async (\n query,\n page,\n limit,\n orderBy,\n endAt,\n startAt,\n ) => Promise.resolve([{id: '1234', name: 'Test Customer', email: '', phone: ''}]),\n get: async (id) => Promise.resolve({id, name: 'Test Customer', email: '', phone: ''}),\n add: async (id, customer) => ({id}),\n update: async (id, updates) => true,\n remove: async (id) => true\n}\n"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "src/workflows/default/workflow.js",
|
|
24
|
+
"contents": "export default async function DefaultWorkflow(\n {\n context,\n customer\n }) {\n return {\n forward: true,\n };\n}\n"
|
|
25
|
+
}
|
|
26
|
+
]
|
package/index.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { mkdirp, copy, dist } from './utils.js';
|
|
4
|
+
|
|
5
|
+
/** @type {import('./types/index.js').create} */
|
|
6
|
+
export async function create(cwd, options) {
|
|
7
|
+
mkdirp(cwd);
|
|
8
|
+
|
|
9
|
+
write_template_files(options.template, options.types, options.name, cwd);
|
|
10
|
+
write_common_files(cwd, options, options.name);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} template
|
|
15
|
+
* @param {'typescript' | 'checkjs' | null} types
|
|
16
|
+
* @param {string} name
|
|
17
|
+
* @param {string} cwd
|
|
18
|
+
*/
|
|
19
|
+
function write_template_files(template, types, name, cwd) {
|
|
20
|
+
const dir = dist(`templates/${template}`);
|
|
21
|
+
copy(`${dir}/assets`, cwd, (name) => name.replace('DOT-', '.'));
|
|
22
|
+
copy(`${dir}/package.json`, `${cwd}/package.json`);
|
|
23
|
+
|
|
24
|
+
const manifest = `${dir}/files.types=${types}.json`;
|
|
25
|
+
const files = /** @type {import('./types/internal.js').File[]} */ (
|
|
26
|
+
JSON.parse(fs.readFileSync(manifest, 'utf-8'))
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
files.forEach((file) => {
|
|
30
|
+
const dest = path.join(cwd, file.name);
|
|
31
|
+
mkdirp(path.dirname(dest));
|
|
32
|
+
|
|
33
|
+
fs.writeFileSync(dest, file.contents.replace(/~TODO~/g, name));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param {string} cwd
|
|
40
|
+
* @param {import('./types/internal.js').Options} options
|
|
41
|
+
* @param {string} name
|
|
42
|
+
*/
|
|
43
|
+
function write_common_files(cwd, options, name) {
|
|
44
|
+
const shared = dist('shared.json');
|
|
45
|
+
const { files } = /** @type {import('./types/internal.js').Common} */ (
|
|
46
|
+
JSON.parse(fs.readFileSync(shared, 'utf-8'))
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const pkg_file = path.join(cwd, 'package.json');
|
|
50
|
+
const pkg = /** @type {any} */ (JSON.parse(fs.readFileSync(pkg_file, 'utf-8')));
|
|
51
|
+
|
|
52
|
+
sort_files(files).forEach((file) => {
|
|
53
|
+
const include = file.include.every((condition) => matches_condition(condition, options));
|
|
54
|
+
const exclude = file.exclude.some((condition) => matches_condition(condition, options));
|
|
55
|
+
|
|
56
|
+
if (exclude || !include) return;
|
|
57
|
+
|
|
58
|
+
if (file.name === 'package.json') {
|
|
59
|
+
const new_pkg = JSON.parse(file.contents);
|
|
60
|
+
merge(pkg, new_pkg);
|
|
61
|
+
} else {
|
|
62
|
+
const dest = path.join(cwd, file.name);
|
|
63
|
+
mkdirp(path.dirname(dest));
|
|
64
|
+
fs.writeFileSync(dest, file.contents);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
pkg.dependencies = sort_keys(pkg.dependencies);
|
|
69
|
+
pkg.devDependencies = sort_keys(pkg.devDependencies);
|
|
70
|
+
pkg.name = to_valid_package_name(name);
|
|
71
|
+
|
|
72
|
+
fs.writeFileSync(pkg_file, JSON.stringify(pkg, null, '\t') + '\n');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {import('./types/internal.js').Condition} condition
|
|
77
|
+
* @param {import('./types/internal.js').Options} options
|
|
78
|
+
* @returns {boolean}
|
|
79
|
+
*/
|
|
80
|
+
function matches_condition(condition, options) {
|
|
81
|
+
if (condition === 'default' || condition === 'skeleton' || condition === 'skeletonlib') {
|
|
82
|
+
return options.template === condition;
|
|
83
|
+
}
|
|
84
|
+
if (condition === 'typescript' || condition === 'checkjs') {
|
|
85
|
+
return options.types === condition;
|
|
86
|
+
}
|
|
87
|
+
return !!options[condition];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {any} target
|
|
92
|
+
* @param {any} source
|
|
93
|
+
*/
|
|
94
|
+
function merge(target, source) {
|
|
95
|
+
for (const key in source) {
|
|
96
|
+
if (key in target) {
|
|
97
|
+
const target_value = target[key];
|
|
98
|
+
const source_value = source[key];
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
typeof source_value !== typeof target_value ||
|
|
102
|
+
Array.isArray(source_value) !== Array.isArray(target_value)
|
|
103
|
+
) {
|
|
104
|
+
throw new Error('Mismatched values');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof source_value === 'object') {
|
|
108
|
+
merge(target_value, source_value);
|
|
109
|
+
} else {
|
|
110
|
+
target[key] = source_value;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
target[key] = source[key];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @param {Record<string, any>} obj */
|
|
119
|
+
function sort_keys(obj) {
|
|
120
|
+
if (!obj) return;
|
|
121
|
+
|
|
122
|
+
/** @type {Record<string, any>} */
|
|
123
|
+
const sorted = {};
|
|
124
|
+
Object.keys(obj)
|
|
125
|
+
.sort()
|
|
126
|
+
.forEach((key) => {
|
|
127
|
+
sorted[key] = obj[key];
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return sorted;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Sort files so that those which apply more generically come first so they
|
|
135
|
+
* can be overwritten by files for more precise cases later.
|
|
136
|
+
*
|
|
137
|
+
* @param {import('./types/internal.js').Common['files']} files
|
|
138
|
+
*/
|
|
139
|
+
function sort_files(files) {
|
|
140
|
+
return files.sort((f1, f2) => {
|
|
141
|
+
const f1_more_generic =
|
|
142
|
+
f1.include.every((include) => f2.include.includes(include)) &&
|
|
143
|
+
f1.exclude.every((exclude) => f2.exclude.includes(exclude));
|
|
144
|
+
const f2_more_generic =
|
|
145
|
+
f2.include.every((include) => f1.include.includes(include)) &&
|
|
146
|
+
f2.exclude.every((exclude) => f1.exclude.includes(exclude));
|
|
147
|
+
const same = f1_more_generic && f2_more_generic;
|
|
148
|
+
const different = !f1_more_generic && !f2_more_generic;
|
|
149
|
+
return same || different ? 0 : f1_more_generic ? -1 : 1;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** @param {string} name */
|
|
154
|
+
function to_valid_package_name(name) {
|
|
155
|
+
return name
|
|
156
|
+
.trim()
|
|
157
|
+
.toLowerCase()
|
|
158
|
+
.replace(/\s+/g, '-')
|
|
159
|
+
.replace(/^[._]/, '')
|
|
160
|
+
.replace(/[^a-z0-9~.-]+/g, '-');
|
|
161
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-scout9",
|
|
3
|
+
"version": "1.0.0-alpha.0.0.1",
|
|
4
|
+
"bin": "./bin.js",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git://github.com/Scout9Official/scout9-nodejs.git"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "node scripts/build-templates",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"types": "types/index.d.ts",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"files": [
|
|
20
|
+
"index.js",
|
|
21
|
+
"dist",
|
|
22
|
+
"bin.js",
|
|
23
|
+
"utils.js",
|
|
24
|
+
"types"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@clack/prompts": "^0.7.0",
|
|
28
|
+
"kleur": "^4.1.5"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"gitignore-parser": "^0.0.2",
|
|
32
|
+
"jest": "^29.7.0",
|
|
33
|
+
"prettier": "^3.1.1",
|
|
34
|
+
"sucrase": "^3.34.0",
|
|
35
|
+
"tiny-glob": "^0.2.9"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Options } from './internal.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a new Scout9 project.
|
|
5
|
+
* @param {string} cwd - Path to the directory to create
|
|
6
|
+
* @param {import('./internal').Options} options
|
|
7
|
+
*/
|
|
8
|
+
export function create(cwd: string, options: Options): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type Options = {
|
|
2
|
+
name: string;
|
|
3
|
+
template: 'default' | 'skeleton' | 'skeletonlib';
|
|
4
|
+
types: 'typescript' | 'checkjs' | null;
|
|
5
|
+
prettier: boolean;
|
|
6
|
+
eslint: boolean;
|
|
7
|
+
playwright: boolean;
|
|
8
|
+
vitest: boolean;
|
|
9
|
+
svelte5?: boolean; // optional to not introduce a breaking change to the `create` API
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type File = {
|
|
13
|
+
name: string;
|
|
14
|
+
contents: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type Condition =
|
|
18
|
+
| 'eslint'
|
|
19
|
+
| 'prettier'
|
|
20
|
+
| 'typescript'
|
|
21
|
+
| 'checkjs'
|
|
22
|
+
| 'playwright'
|
|
23
|
+
| 'vitest'
|
|
24
|
+
| 'skeleton'
|
|
25
|
+
| 'default'
|
|
26
|
+
| 'skeletonlib'
|
|
27
|
+
| 'svelte5';
|
|
28
|
+
|
|
29
|
+
export type Common = {
|
|
30
|
+
files: Array<{
|
|
31
|
+
name: string;
|
|
32
|
+
include: Condition[];
|
|
33
|
+
exclude: Condition[];
|
|
34
|
+
contents: string;
|
|
35
|
+
}>;
|
|
36
|
+
};
|
package/utils.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/** @param {string} dir */
|
|
6
|
+
export function mkdirp(dir) {
|
|
7
|
+
try {
|
|
8
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
9
|
+
} catch (e) {
|
|
10
|
+
if (/** @type {any} */ (e).code === 'EEXIST') return;
|
|
11
|
+
throw e;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @param {string} path */
|
|
16
|
+
export function rimraf(path) {
|
|
17
|
+
(fs.rmSync || fs.rmdirSync)(path, { recursive: true, force: true });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @template T
|
|
22
|
+
* @param {T} x
|
|
23
|
+
*/
|
|
24
|
+
function identity(x) {
|
|
25
|
+
return x;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} from
|
|
30
|
+
* @param {string} to
|
|
31
|
+
* @param {(basename: string) => string} rename
|
|
32
|
+
*/
|
|
33
|
+
export function copy(from, to, rename = identity) {
|
|
34
|
+
if (!fs.existsSync(from)) return;
|
|
35
|
+
|
|
36
|
+
const stats = fs.statSync(from);
|
|
37
|
+
|
|
38
|
+
if (stats.isDirectory()) {
|
|
39
|
+
fs.readdirSync(from).forEach((file) => {
|
|
40
|
+
copy(path.join(from, file), path.join(to, rename(file)));
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
mkdirp(path.dirname(to));
|
|
44
|
+
fs.copyFileSync(from, to);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @param {string} path */
|
|
49
|
+
export function dist(path) {
|
|
50
|
+
return fileURLToPath(new URL(`./dist/${path}`, import.meta.url).href);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @type {string} */
|
|
54
|
+
export const package_manager = get_package_manager() || 'npm';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Supports npm, pnpm, Yarn, cnpm, bun and any other package manager that sets the
|
|
58
|
+
* npm_config_user_agent env variable.
|
|
59
|
+
* Thanks to https://github.com/zkochan/packages/tree/main/which-pm-runs for this code!
|
|
60
|
+
*/
|
|
61
|
+
function get_package_manager() {
|
|
62
|
+
if (!process.env.npm_config_user_agent) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const user_agent = process.env.npm_config_user_agent;
|
|
66
|
+
const pm_spec = user_agent.split(' ')[0];
|
|
67
|
+
const separator_pos = pm_spec.lastIndexOf('/');
|
|
68
|
+
const name = pm_spec.substring(0, separator_pos);
|
|
69
|
+
return name === 'npminstall' ? 'cnpm' : name;
|
|
70
|
+
}
|