Compare commits
85 Commits
step-3-wor
...
handle-use
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
779e2d61f4 | ||
|
|
5e92314938 | ||
|
|
3b5c287ef9 | ||
|
|
7ffbf42da9 | ||
|
|
6b4256b7ab | ||
|
|
e712693dd0 | ||
|
|
220d76c2be | ||
|
|
2870695b25 | ||
|
|
bca71604fb | ||
|
|
84edb5563f | ||
|
|
9b58f7745b | ||
|
|
b0737efb4e | ||
|
|
5d2a15bc93 | ||
|
|
145fff3b51 | ||
|
|
4f6c714fa3 | ||
|
|
f714fdf70a | ||
|
|
adc1f1c099 | ||
|
|
c0a177d39b | ||
|
|
3700d9bb58 | ||
|
|
7a5ddc6b52 | ||
|
|
39b8e7608e | ||
|
|
a8ffe0a5c0 | ||
|
|
def591224e | ||
|
|
d8b2f5f0b4 | ||
|
|
dc2c8f384e | ||
|
|
cc579133c0 | ||
|
|
0a8eb2e280 | ||
|
|
6b26db3d18 | ||
|
|
3202bf5f0b | ||
|
|
370edd6ef0 | ||
|
|
0d858ad1c7 | ||
|
|
c6cd49a66f | ||
|
|
97b6755f2f | ||
|
|
b2386ea0d6 | ||
|
|
2ae983d211 | ||
|
|
b1a853c363 | ||
|
|
d58d4b89e3 | ||
|
|
2c6953fe97 | ||
|
|
af19108e9c | ||
|
|
a00859c594 | ||
|
|
085a0324b3 | ||
|
|
d8799fa40d | ||
|
|
de0a4f3176 | ||
|
|
48578d3ffe | ||
|
|
e2d648980b | ||
|
|
b73086291c | ||
|
|
434d45248c | ||
|
|
00272ec67d | ||
|
|
0727328e58 | ||
|
|
e2d76ff03e | ||
|
|
9cff3cd9ae | ||
|
|
2f82709f11 | ||
|
|
f6bf3a05b2 | ||
|
|
4b594898b1 | ||
|
|
b07a9e21b3 | ||
|
|
a570640fe1 | ||
|
|
9e4b06bd4c | ||
|
|
6bfd4adcaf | ||
|
|
48badce0f0 | ||
|
|
68287d49ff | ||
|
|
2f59e12aa7 | ||
|
|
3e37c93395 | ||
|
|
cd041c0131 | ||
|
|
0607f1e98d | ||
|
|
5db270d957 | ||
|
|
389a71b05a | ||
|
|
e5783740cf | ||
|
|
1a5f4586a8 | ||
|
|
a78189f1a1 | ||
|
|
cd938c3981 | ||
|
|
2bce02ab4e | ||
|
|
6859f567a9 | ||
|
|
6e7bccea86 | ||
|
|
7e4b959ffa | ||
|
|
e1f315cb81 | ||
|
|
49d30f00f8 | ||
|
|
1b04e72b98 | ||
|
|
07857fd2f4 | ||
|
|
7f56a28509 | ||
|
|
ff7e564d2e | ||
|
|
bbec4e9940 | ||
|
|
b80843cb97 | ||
|
|
4c8c1c5e0e | ||
|
|
7d79c03d15 | ||
|
|
44ef80b7dd |
107
README.md
107
README.md
@@ -1,12 +1,103 @@
|
||||
first terminal
|
||||
cd web
|
||||
npm install
|
||||
npm start
|
||||
To obtain client ID and secret :
|
||||
https://developer.amazon.com/lwa/sp/overview.html
|
||||
Click create new security profile, and add whitelist redirect uri : https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO
|
||||
|
||||
second terminal
|
||||
cd backend
|
||||
npm install
|
||||
node express.js
|
||||
|
||||
To obtain new Auth Code :
|
||||
|
||||
https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.8c183daec15c488c9126b62bda9f7832&scope=alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test&response_type=code&redirect_uri=https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO
|
||||
|
||||
Response URL (Decoded) :
|
||||
|
||||
https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO?code=ANCgZUfEFdlRRkpSNFuA&scope=alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test
|
||||
|
||||
Code : ANCgZUfEFdlRRkpSNFuA
|
||||
=======================================
|
||||
|
||||
Now to get Access Token :
|
||||
|
||||
Send a POST request to https://api.amazon.com/auth/o2/token with the following parameters
|
||||
|
||||
- HTTP Header Parameters
|
||||
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
- HTTP Body Parameters
|
||||
|
||||
grant_type: authorization_code
|
||||
code: The authorization code that was returned in the response.
|
||||
client_id: The product’s client ID. To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
client_secret: The product’s client secret. To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
redirect_uri: One of the return URIs that you added to your app’s security profile when signing up.
|
||||
|
||||
Response :
|
||||
|
||||
{
|
||||
"access_token": "Atza|IwEBIBe6gDqrrowEEav6N-_6s4NztYeP3oG8PGWmu8ZiZw6lbOh3wNla3TK6pY-VEpT1d8an-dVf_n3kXJzVFsNo_4xBfZyFHGoCTDTFjs3yBRul4PVdBOhwwiH3-sgRLcUofZbe2oE06GmTcbfYtaStfXpQI5dfpldfnsJg_CvhSA6AHb_snJT3F6lyXzbV076d_3cYUMJxFldJGnYcviNHHxjjmuQTD06hhGzCbAxxe9eBmkuopRsNfyedLT2UlKP_ublah9CUGA3AdIX_3Iuke82jMwGnNl9gv7pbaDNEjAbj7IQSl3B08uuREtJq-oTBOjALNXRvFxTJmQjZwXNf9eHC7fSHJDdEPdZQU0AcffRQObAyAkUuL6Jv39OHzhb3Q64-zzoyODqnJyLP5SQZ2JVF53Kc_cTBqjIc9pXljqe7yEVk6JDs7q1zKbBibx_AQm57TO79IzWyLBzBMlYL5HdTsqEfRzLeDw2tws-hGMgkx2HWfdbYnmf5Qb4SyIhzvmmdfPLg3MVKTxjIBu1rx0xf3n0PLZP1EO6jsJPoMRPg77Gm4oit5Zp6s37ek3A3Vxh-ntoASpkrkxGTG9kVtRNt",
|
||||
"refresh_token": "Atzr|IwEBICA3kDhfSJxlwvnQp9AD1o115AC_KBbFd5GBg8oN_QHWn2or5xFQ09BruuK6a07tGHtTt_9q2Y21mnOMH4RDtYXTVG9ADgLE6mHWKZFxYVwt3kHMiUJdY5lJcsOtWLoblrS-bJ0BEXXK5nVDt_bSI5IB7NUf-9QVZxhovRH_ANSxdTjJT0_rMIAZY3WEj68FEap49q_pg72BhnxHVZD2TC3zvX96_DN65HE5SoSgT7OiMAeiJewB_SyemW_HxBwaB-_X-G1ifOtnrzZ4gXTpOrEUlHI2YPuvRMBMtmz1h-nXDZYv3vwU3RA57Qj_ZNVcScj8_RXf2xq8w48v0PzZFXYBSalfnqPq6eUvSSbAJUp6bB8y596JlvR5dFQe_Z--X0Gkfo85IcyrI9D44vK9sJhrGhCVi2FDDa8pHczmNSen99JYZvDif-zpYzgbcymAkOV0gC7JvYMxlZfETT3NTBy7eVA7fJI1SZaeA_qW49xRcBkZBu5gkqTpeGWUU1cGr2aXRVVmXGM22NfV5E7KzvEBsCeHml_tCfxZeKY8Msd8hJb0Cd59u-_hsuc8oNjsOpIdFF976dY3uTmAgHWpG2PH",
|
||||
"token_type": "bearer",
|
||||
"expires_in": 3600
|
||||
}
|
||||
|
||||
================================
|
||||
|
||||
Now to get new Access token using refresh token :
|
||||
|
||||
Send a POST request to https://api.amazon.com/auth/o2/token with the following parameters:
|
||||
|
||||
- HTTP Header Parameters
|
||||
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
- HTTP Body Parameters
|
||||
|
||||
grant_type: refresh_token
|
||||
refresh_token: The URL-encoded refresh token returned with the last request for a new access token.
|
||||
client_id: To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
client_secret: The website’s client secret. To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
|
||||
Response :
|
||||
|
||||
{
|
||||
"access_token": "Atza|IwEBILtBe3hrHovrMx7Oivng-RB2EKzvCm_epXJE2HXPMQzXTFqK10Zrqt-Z8paeRoLQBqbLCmqWvcr5RTNgw9qjtfzOTsOrXC1VKqKmxpqHTrJyn2TLGsCzFjBDfADNjCyufWTf2ZlsSzjxW2GiqCHlwoPSd9pFrLavtRThrm1J-5KvnFrj-yD-tYTSwrgX5W5p2SrjQxoE3aP5b96z6p8GvCL9lM1pddafAxkHb22A3IzR-pYGmEijb4ksRuaIf4WCNwssWV6GBIB2oJA5CU-Dtd2mOZZ5-dYpSSeCHyGumTYecTxxMVSdiVjCqB8WT6AtvvutWFQQoldHjJmIwBsTZP-iQcl-UyajOZJ03GqRUym5Hp-49uByzVG-MfR_Z5qVmYjjsLQEOLCY9kPVnmRGnOTj6YPjrHXibd6P8TQOMh4VTcgFpg-afKKABP6EeDwok1t2ivuYh5OJju-B1A6gzhMi4vQJYKq107e0QMYBBhrf_OqCgMbfnQZ8j40qocVGID5YWv8uk5wKyI61LrbzrTltmzxzNemzqbSBzwAlfNS6GW-jVjg8svsi1lb_EVRbhyOoWJWX3mEd-5GDYyUcyInleiAR0aIHVP94pZxqdiCamA",
|
||||
"refresh_token": "Atzr|IwEBICA3kDhfSJxlwvnQp9AD1o115AC_KBbFd5GBg8oN_QHWn2or5xFQ09BruuK6a07tGHtTt_9q2Y21mnOMH4RDtYXTVG9ADgLE6mHWKZFxYVwt3kHMiUJdY5lJcsOtWLoblrS-bJ0BEXXK5nVDt_bSI5IB7NUf-9QVZxhovRH_ANSxdTjJT0_rMIAZY3WEj68FEap49q_pg72BhnxHVZD2TC3zvX96_DN65HE5SoSgT7OiMAeiJewB_SyemW_HxBwaB-_X-G1ifOtnrzZ4gXTpOrEUlHI2YPuvRMBMtmz1h-nXDZYv3vwU3RA57Qj_ZNVcScj8_RXf2xq8w48v0PzZFXYBSalfnqPq6eUvSSbAJUp6bB8y596JlvR5dFQe_Z--X0Gkfo85IcyrI9D44vK9sJhrGhCVi2FDDa8pHczmNSen99JYZvDif-zpYzgbcymAkOV0gC7JvYMxlZfETT3NTBy7eVA7fJI1SZaeA_qW49xRcBkZBu5gkqTpeGWUU1cGr2aXRVVmXGM22NfV5E7KzvEBsCeHml_tCfxZeKY8Msd8hJb0Cd59u-_hsuc8oNjsOpIdFF976dY3uTmAgHWpG2PH",
|
||||
"token_type": "bearer",
|
||||
"expires_in": 3600
|
||||
}
|
||||
|
||||
=======================
|
||||
=======================
|
||||
|
||||
Prerequests for step 3 (run on server):
|
||||
requires running mongodb service
|
||||
|
||||
Database (tellall) with collection (skill_list)
|
||||
* Insert dummy skill with : db.skill_list.insert({"skillID" : "amzn1.ask.skill.efbf0564-a732-4ba9-958f-57939138adae", "intents" : [ { "intentName" : "GetFirstQuestion", "questionExplanation" : "", "questions" : [ "tell me something about projects", "tell me all about projects" ], "answer" : "blablabla bla bla" }, { "intentName" : "GetThirdQuestion", "questionExplanation" : "", "questions" : [ "Give me third question" ], "answer" : "This is answer to the third question" } ], "invocationName" : "Saburly", "invocationAnswer" : "We are Saburly team one" })
|
||||
|
||||
*obtain _id and change in web/src/App.js, and also skill_db_id in backend/config.js
|
||||
*enter web/ dir and run "npm run build"
|
||||
|
||||
Database (tellall) with collection (token_list)
|
||||
* Insert tokens with : db.token_list.insert({"id" : 1, "refresh_token" : "...", "access_token" : "...", "expires_in" : 1515173601.754 })
|
||||
(Change refresh_token and access_token dots with real ones)
|
||||
|
||||
Set skill_id, client_id and client_secret to appropriate values in backend/config.js
|
||||
Set base_url to "tellall.saburly.com" in web/src/config.
|
||||
|
||||
Start backend service from backend/ running "node express.js"
|
||||
|
||||
|
||||
======
|
||||
for local testing :
|
||||
|
||||
first terminal :
|
||||
*cd web
|
||||
*npm start
|
||||
|
||||
second terminal :
|
||||
* cd backend
|
||||
*npm install
|
||||
*node express.js
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"languageModel": {
|
||||
"intents": [
|
||||
{
|
||||
"name": "AMAZON.CancelIntent",
|
||||
"samples": []
|
||||
},
|
||||
{
|
||||
"name": "AMAZON.HelpIntent",
|
||||
"samples": []
|
||||
},
|
||||
{
|
||||
"name": "AMAZON.StopIntent",
|
||||
"samples": []
|
||||
},
|
||||
{
|
||||
"name": "GetProcessIntent",
|
||||
"samples": [
|
||||
"tell me your process",
|
||||
"what is your process",
|
||||
"how do you work",
|
||||
"about your proces"
|
||||
],
|
||||
"slots": []
|
||||
},
|
||||
{
|
||||
"name": "GetProjectsIntent",
|
||||
"samples": [
|
||||
"list me your projects",
|
||||
"show me what you have done",
|
||||
"what did you do so far",
|
||||
"what are your projects",
|
||||
"your project"
|
||||
],
|
||||
"slots": []
|
||||
},
|
||||
{
|
||||
"name": "GetServicesIntent",
|
||||
"samples": [
|
||||
"what are your services",
|
||||
"what services do you ofer",
|
||||
"what you do",
|
||||
"your service",
|
||||
"tell me service"
|
||||
],
|
||||
"slots": []
|
||||
},
|
||||
{
|
||||
"name": "GetTechnologiesIntent",
|
||||
"samples": [
|
||||
"list me your technologies",
|
||||
"give me your technologies",
|
||||
"what you know"
|
||||
],
|
||||
"slots": []
|
||||
}
|
||||
],
|
||||
"invocationName": "saburly"
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
var config = {};
|
||||
|
||||
config.dbURL = 'mongodb://localhost:27017/tellall';
|
||||
config.PORT = 5000;
|
||||
|
||||
config.TOKEN = 'Atza|IwEBIBe6gDqrrowEEav6N-_6s4NztYeP3oG8PGWmu8ZiZw6lbOh3wNla3TK6pY-VEpT1d8an-dVf_n3kXJzVFsNo_4xBfZyFHGoCTDTFjs3yBRul4PVdBOhwwiH3-sgRLcUofZbe2oE06GmTcbfYtaStfXpQI5dfpldfnsJg_CvhSA6AHb_snJT3F6lyXzbV076d_3cYUMJxFldJGnYcviNHHxjjmuQTD06hhGzCbAxxe9eBmkuopRsNfyedLT2UlKP_ublah9CUGA3AdIX_3Iuke82jMwGnNl9gv7pbaDNEjAbj7IQSl3B08uuREtJq-oTBOjALNXRvFxTJmQjZwXNf9eHC7fSHJDdEPdZQU0AcffRQObAyAkUuL6Jv39OHzhb3Q64-zzoyODqnJyLP5SQZ2JVF53Kc_cTBqjIc9pXljqe7yEVk6JDs7q1zKbBibx_AQm57TO79IzWyLBzBMlYL5HdTsqEfRzLeDw2tws-hGMgkx2HWfdbYnmf5Qb4SyIhzvmmdfPLg3MVKTxjIBu1rx0xf3n0PLZP1EO6jsJPoMRPg77Gm4oit5Zp6s37ek3A3Vxh-ntoASpkrkxGTG9kVtRNt';
|
||||
config.REFRESH_TOKEN = 'Atzr|IwEBICA3kDhfSJxlwvnQp9AD1o115AC_KBbFd5GBg8oN_QHWn2or5xFQ09BruuK6a07tGHtTt_9q2Y21mnOMH4RDtYXTVG9ADgLE6mHWKZFxYVwt3kHMiUJdY5lJcsOtWLoblrS-bJ0BEXXK5nVDt_bSI5IB7NUf-9QVZxhovRH_ANSxdTjJT0_rMIAZY3WEj68FEap49q_pg72BhnxHVZD2TC3zvX96_DN65HE5SoSgT7OiMAeiJewB_SyemW_HxBwaB-_X-G1ifOtnrzZ4gXTpOrEUlHI2YPuvRMBMtmz1h-nXDZYv3vwU3RA57Qj_ZNVcScj8_RXf2xq8w48v0PzZFXYBSalfnqPq6eUvSSbAJUp6bB8y596JlvR5dFQe_Z--X0Gkfo85IcyrI9D44vK9sJhrGhCVi2FDDa8pHczmNSen99JYZvDif-zpYzgbcymAkOV0gC7JvYMxlZfETT3NTBy7eVA7fJI1SZaeA_qW49xRcBkZBu5gkqTpeGWUU1cGr2aXRVVmXGM22NfV5E7KzvEBsCeHml_tCfxZeKY8Msd8hJb0Cd59u-_hsuc8oNjsOpIdFF976dY3uTmAgHWpG2PH';
|
||||
config.TOKEN_EXPIRES_IN = 1515100500;
|
||||
|
||||
config.SKILL_ID = 'amzn1.ask.skill.efbf0564-a732-4ba9-958f-57939138adae';
|
||||
//config.SKILL_DB_ID = '5a5016e775becaef2015da10'; //for server
|
||||
config.SKILL_DB_ID = '5a232fb86ce046c749739455'; //for local
|
||||
|
||||
config.CLIENT_ID = 'amzn1.application-oa2-client.c748ca56ded04a95b236979898585ff7';
|
||||
config.CLIENT_SECRET = '6dea8125cecd049d3c4cff7bb5bdfd3ff17bc6fed246c4c8f6b519d9ed08d0b3';
|
||||
|
||||
module.exports = config;
|
||||
30
backend/config/config.js
Normal file
30
backend/config/config.js
Normal file
@@ -0,0 +1,30 @@
|
||||
var config = {};
|
||||
|
||||
config.DB_URL = 'mongodb://localhost:27017/tellall';
|
||||
config.PORT = 5000;
|
||||
|
||||
//Bilal TOKENS
|
||||
//config.TOKEN = 'Atza|IwEBIBe6gDqrrowEEav6N-_6s4NztYeP3oG8PGWmu8ZiZw6lbOh3wNla3TK6pY-VEpT1d8an-dVf_n3kXJzVFsNo_4xBfZyFHGoCTDTFjs3yBRul4PVdBOhwwiH3-sgRLcUofZbe2oE06GmTcbfYtaStfXpQI5dfpldfnsJg_CvhSA6AHb_snJT3F6lyXzbV076d_3cYUMJxFldJGnYcviNHHxjjmuQTD06hhGzCbAxxe9eBmkuopRsNfyedLT2UlKP_ublah9CUGA3AdIX_3Iuke82jMwGnNl9gv7pbaDNEjAbj7IQSl3B08uuREtJq-oTBOjALNXRvFxTJmQjZwXNf9eHC7fSHJDdEPdZQU0AcffRQObAyAkUuL6Jv39OHzhb3Q64-zzoyODqnJyLP5SQZ2JVF53Kc_cTBqjIc9pXljqe7yEVk6JDs7q1zKbBibx_AQm57TO79IzWyLBzBMlYL5HdTsqEfRzLeDw2tws-hGMgkx2HWfdbYnmf5Qb4SyIhzvmmdfPLg3MVKTxjIBu1rx0xf3n0PLZP1EO6jsJPoMRPg77Gm4oit5Zp6s37ek3A3Vxh-ntoASpkrkxGTG9kVtRNt';
|
||||
//config.REFRESH_TOKEN = 'Atzr|IwEBICA3kDhfSJxlwvnQp9AD1o115AC_KBbFd5GBg8oN_QHWn2or5xFQ09BruuK6a07tGHtTt_9q2Y21mnOMH4RDtYXTVG9ADgLE6mHWKZFxYVwt3kHMiUJdY5lJcsOtWLoblrS-bJ0BEXXK5nVDt_bSI5IB7NUf-9QVZxhovRH_ANSxdTjJT0_rMIAZY3WEj68FEap49q_pg72BhnxHVZD2TC3zvX96_DN65HE5SoSgT7OiMAeiJewB_SyemW_HxBwaB-_X-G1ifOtnrzZ4gXTpOrEUlHI2YPuvRMBMtmz1h-nXDZYv3vwU3RA57Qj_ZNVcScj8_RXf2xq8w48v0PzZFXYBSalfnqPq6eUvSSbAJUp6bB8y596JlvR5dFQe_Z--X0Gkfo85IcyrI9D44vK9sJhrGhCVi2FDDa8pHczmNSen99JYZvDif-zpYzgbcymAkOV0gC7JvYMxlZfETT3NTBy7eVA7fJI1SZaeA_qW49xRcBkZBu5gkqTpeGWUU1cGr2aXRVVmXGM22NfV5E7KzvEBsCeHml_tCfxZeKY8Msd8hJb0Cd59u-_hsuc8oNjsOpIdFF976dY3uTmAgHWpG2PH';
|
||||
|
||||
//Saburly TOKENS
|
||||
config.TOKEN = 'Atza|IwEBIABS0RvlVshGGO64X0tabhUuzpJKjbWNgxpRiy7YTftFD_lWlp-cbeXuVjRAu8kior2W2C5swf_rEHYvELQXdw78gB9WJQh4ITncPgqNCxvEnwVpIXiyeC_O287DRErnTYbI3s34i4NcxrXzobB8fIpTZxOkg6BI6vQGvvaiNLsTim2ElDYgAEmdgTN77llcMai521aovDqEw_XFc6GspeXhiGKxRomCMIL2UaT649owapDQ3y3Ug9eHvEaBzqjYdOUAtRtv19BGkG8YPs3npHmP5AD0Oc3ByCfrofcGk7fdd_nq28pRX6h4LXk4ylM279qlneWh9EErsWh8vtWuGEGusnDxW17OzEzf7HuwNDqdCJ6gCrIEkZaHISrSQ-vTsYGhKbv0z4nNjf_W_aoc9UJr9LnISCXx424R--iGDKZXhYWlZRjaiHsXE33MpS_M-sdN6GXYQwIjanTUahVXh5h-IBam5uJzTejE6CkIh5iUJ6um2IlDelJRMGS-T_aaG3zUvEagvEd9V9Z5mVN_kmO8bH4H2VefZuFGHRsCPa6SoLrlN0rkXK5fMw-zXfV2MHvQFdkgqYqGKxiEwWJ-g4n1ZrcPtWQowHT2z2yWrfnM2A6g8GIdPT23znmRcrdz4EU';
|
||||
config.REFRESH_TOKEN = 'Atzr|IwEBIENdBZntrzvJYesv8SGhnty4Nyk2ZySL09elw5N0wH8S1Brz1UgIYLqenw3sKKxnc-VrIUbNtl1Ka4GDKwcTr2fDU_AbKQ6YXzeRBrfRQVvNOeCtjZE8P6Kg1PxAeQoCsqo7WPxK8ZdUaLwPjt_xiZ1FXtr01g-211PJs4KEg5jyF5nY2S14jA_TbwDW6ihpNqWd6ZklTZSRaOeSGa1mXZCSZ5yTsZIQV1Pn0fKhCXtcVg2L833YqRmextmHij4-2NtBQdW3gif5MPdhYjTqDNwgxO3OOagK1uSFqXOnMcmEDnxZuQQApugfDzClfN6DiDALCKN4dVAX8-OU_L2xsUkKiFP9rQjvHWJoRFBT1FpXjBfoVyzM1AaJ6C83WX6SjOBE0hhikQKIaPSe1ikK8_MzOIs2wqLLPnLGnKj3kcKMkDmY6DMgxfWj2H0hwLy0oZ7_qykS7wUHMGjRO5yScuBWFIr0RFFu00GS7zrKjkhFc_E4ZBBKskn0gywS-5pogo0U1rQtLg8lQJsVbxXQwtq2TxkGFMBiVxtQcXtHM1qbCVXpZQbk7ezxvasj4yAIsF4H7KBiZSGmWHkk4yADykWJSntTjFcM2wG0wSiEYoYzJQ';
|
||||
config.TOKEN_EXPIRES_IN = 1515100500;
|
||||
|
||||
|
||||
|
||||
//config.SKILL_ID = 'amzn1.ask.skill.efbf0564-a732-4ba9-958f-57939138adae'; //bilal
|
||||
config.SKILL_ID = 'amzn1.ask.skill.2445552d-954d-4cd6-b77f-295368e02842'; //saburly
|
||||
//config.SKILL_DB_ID = '5a5016e775becaef2015da10'; //for server
|
||||
config.SKILL_DB_ID = '5a232fb86ce046c749739455'; //for local
|
||||
|
||||
//Bilal
|
||||
//config.CLIENT_ID = 'amzn1.application-oa2-client.c748ca56ded04a95b236979898585ff7';
|
||||
//config.CLIENT_SECRET = '6dea8125cecd049d3c4cff7bb5bdfd3ff17bc6fed246c4c8f6b519d9ed08d0b3';
|
||||
|
||||
//Saburly
|
||||
config.CLIENT_ID = 'amzn1.application-oa2-client.8c183daec15c488c9126b62bda9f7832';
|
||||
config.CLIENT_SECRET = '3acaa0755291132ee11e1cceaa100feef96a0244662df712a52189199cc655de';
|
||||
|
||||
module.exports = config;
|
||||
61
backend/config/constants.js
Normal file
61
backend/config/constants.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const constants = {};
|
||||
|
||||
constants.amazonResultCodes = {
|
||||
OK: 200,
|
||||
ACCEPTED: 202,
|
||||
BAD_REQUEST: 400,
|
||||
UNAUTHORIZED: 401,
|
||||
NOT_FOUND: 404,
|
||||
CONFLICT: 409,
|
||||
PAYLOAD_TOO_LARGE: 413,
|
||||
};
|
||||
|
||||
constants.apiResultCodes = {
|
||||
GENERIC_ERROR: -1,
|
||||
OK: 0,
|
||||
AMAZON_ERROR: 1, //amazon api works, but error is some of the amazonResultCodes
|
||||
AMAZON_FAIL: 2, //amazon api doesn't work
|
||||
DATABASE_ERROR: 3,
|
||||
NO_SKILL: 4,
|
||||
INCONSISTENT_STATE: 5,
|
||||
INVALID_SKILL: 6,
|
||||
};
|
||||
|
||||
constants.HTTPResultCodes = {
|
||||
INTERNAL_SERVER_ERROR: 500,
|
||||
};
|
||||
|
||||
constants.SKILL_ID_LENGTH = 24;
|
||||
|
||||
constants.voiceResponseStrings = {
|
||||
QUESTION_NOT_FOUND: 'Sorry, I didnt understand',
|
||||
GENERIC_CONTINUE: 'Say something to continue',
|
||||
DIDNT_ASK_ANYTHING: 'There was no question to answer to',
|
||||
};
|
||||
|
||||
//Timing is given in [ms]
|
||||
constants.voiceResponseTimings = {
|
||||
PAUSE_BETWEEN_QUESTIONS: 650,
|
||||
PAUSE_AFTER_WELCOME_MESSAGE: 650,
|
||||
};
|
||||
|
||||
constants.stringConstraints = {
|
||||
INTENT_EXPLANATION_MAX_LENGTH: 70,
|
||||
|
||||
INTENT_NAME_MAX_LENGTH: 30,
|
||||
INTENT_NAME_MIN_LENGTH: 2,
|
||||
|
||||
QUESTION_MAX_LENGTH: 150,
|
||||
QUESTION_MIN_LENGTH: 2,
|
||||
|
||||
ANSWER_MAX_LENGTH: 150,
|
||||
ANSWER_MIN_LENGTH: 2,
|
||||
|
||||
INVOCATION_NAME_MAX_LENGTH: 50,
|
||||
INVOCATION_NAME_MIN_LENGTH: 2,
|
||||
INVOCATION_ANSWER_MAX_LENGTH: 100,
|
||||
|
||||
EMAIL_MAX_LENGTH: 100,
|
||||
};
|
||||
|
||||
module.exports = constants;
|
||||
14
backend/config/email.js
Normal file
14
backend/config/email.js
Normal file
@@ -0,0 +1,14 @@
|
||||
var config = {};
|
||||
|
||||
config.PORT = 587;
|
||||
config.SMTP_HOST = 'smtp.mail.com';
|
||||
config.SECURE = false;
|
||||
config.AUTH = {
|
||||
user: 'saburly@mail.com',
|
||||
pass: 'KeepSaburly',
|
||||
};
|
||||
|
||||
config.FROM_EMAIL = 'saburly@mail.com';
|
||||
config.SUBJECT = 'Message from Saburly service';
|
||||
|
||||
module.exports = config;
|
||||
6
backend/controllers/index.js
Normal file
6
backend/controllers/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
var express = require ('express'), router = express.Router ();
|
||||
|
||||
router.use ('/skill', require ('./skill'));
|
||||
router.use ('/saburly', require('./saburlyEntryPoint'));
|
||||
|
||||
module.exports = router;
|
||||
9
backend/controllers/saburlyEntryPoint.js
Normal file
9
backend/controllers/saburlyEntryPoint.js
Normal file
@@ -0,0 +1,9 @@
|
||||
var express = require ('express'), router = express.Router ();
|
||||
var bodyParser = require ('body-parser');
|
||||
var alexa = require ('../models/alexa');
|
||||
|
||||
router.post ('/', bodyParser.json (), async (req, res) => {
|
||||
alexa.run (req, res);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
145
backend/controllers/skill.js
Normal file
145
backend/controllers/skill.js
Normal file
@@ -0,0 +1,145 @@
|
||||
var express = require ('express'), router = express.Router ();
|
||||
const constants = require ('../config/constants');
|
||||
var databaseHelper = require ('../helpers/database');
|
||||
var amazonHelper = require ('../helpers/amazon');
|
||||
var skillValidator = require('../helpers/skillValidator');
|
||||
var bodyParser = require ('body-parser');
|
||||
var alexa = require ('../models/alexa');
|
||||
|
||||
router.get ('/:id', async (req, res, next) => {
|
||||
const id = req.params.id;
|
||||
|
||||
if (id.length !== constants.SKILL_ID_LENGTH) {
|
||||
res.json ([]);
|
||||
} else {
|
||||
databaseHelper
|
||||
.getSkill (id)
|
||||
.then (result => {
|
||||
res.json (result);
|
||||
})
|
||||
.catch (err => {
|
||||
res.json ([]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.put ('/:id', bodyParser.json (), async (req, res, next) => {
|
||||
let id = req.params.id;
|
||||
let dataFromWeb = JSON.stringify (req.body);
|
||||
let skill = JSON.parse (dataFromWeb);
|
||||
let updateOnAmazon = skill.updateOnAmazon;
|
||||
|
||||
delete skill.updateOnAmazon;
|
||||
delete skill._id;
|
||||
|
||||
//Validate skill
|
||||
if (!skillValidator.validateSkill(skill)){
|
||||
//skill not valid
|
||||
res
|
||||
.status (
|
||||
constants.HTTPResultCodes.INTERNAL_SERVER_ERROR
|
||||
)
|
||||
.json ({
|
||||
result: constants.apiResultCodes.INVALID_SKILL,
|
||||
message: '',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//First get current skill from DB
|
||||
databaseHelper
|
||||
.getSkill (id)
|
||||
.then (currentSkillState => {
|
||||
//Now let's update skill in DB
|
||||
databaseHelper
|
||||
.updateSkill (id, skill)
|
||||
.then (() => {
|
||||
//Ok, done, now update skill on Amazon (if needed)
|
||||
if (updateOnAmazon) {
|
||||
//We need to update skill on Amazon
|
||||
amazonHelper
|
||||
.updateSkill (skill)
|
||||
.then (amazonResult => {
|
||||
if (
|
||||
amazonResult === constants.amazonResultCodes.OK ||
|
||||
amazonResult === constants.amazonResultCodes.ACCEPTED
|
||||
) {
|
||||
res.json ({result: constants.apiResultCodes.OK, message: ''});
|
||||
alexa.updateModel ();
|
||||
} else {
|
||||
//Update on amazon failed, revert changes in database and send error to user
|
||||
databaseHelper
|
||||
.updateSkill (id, currentSkillState)
|
||||
.then (() => {
|
||||
res
|
||||
.status (
|
||||
constants.HTTPResultCodes.INTERNAL_SERVER_ERROR
|
||||
)
|
||||
.json ({
|
||||
result: constants.apiResultCodes.AMAZON_ERROR,
|
||||
message: amazonResult,
|
||||
});
|
||||
})
|
||||
.catch (() => {
|
||||
//This should never happen, something is seriously wrong, like no database connection
|
||||
res
|
||||
.status (
|
||||
constants.HTTPResultCodes.INTERNAL_SERVER_ERROR
|
||||
)
|
||||
.json ({
|
||||
result: constants.apiResultCodes.INCONSISTENT_STATE,
|
||||
message: '',
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch (e => {
|
||||
//Update on amazon failed, revert changes in database and send error to user
|
||||
databaseHelper
|
||||
.updateSkill (id, currentSkillState)
|
||||
.then (() => {
|
||||
res
|
||||
.status (constants.HTTPResultCodes.INTERNAL_SERVER_ERROR)
|
||||
.json ({
|
||||
result: constants.apiResultCodes.AMAZON_FAIL,
|
||||
message: e,
|
||||
});
|
||||
})
|
||||
.catch (() => {
|
||||
//This should never happen, something is seriously wrong, like no database connection
|
||||
res
|
||||
.status (constants.HTTPResultCodes.INTERNAL_SERVER_ERROR)
|
||||
.json ({
|
||||
result: constants.apiResultCodes.INCONSISTENT_STATE,
|
||||
message: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
//No need to update on Amazon, tell to user it's ok
|
||||
res.json ({result: constants.apiResultCodes.OK, message: ''});
|
||||
alexa.updateModel ();
|
||||
}
|
||||
})
|
||||
.catch (() => {
|
||||
//Update in database didn't go well, no need to revert since it failed to write in the first place
|
||||
//just send error to user
|
||||
res
|
||||
.status (
|
||||
constants.HTTPResultCodes.INTERNAL_SERVER_ERROR
|
||||
)
|
||||
.json ({
|
||||
result: constants.apiResultCodes.DATABASE_ERROR,
|
||||
message: '',
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch (e => {
|
||||
//I don't know why, but something went wrong, possibly ID of skill is wrong, doesn't exist in DB
|
||||
res
|
||||
.status (constants.HTTPResultCodes.INTERNAL_SERVER_ERROR)
|
||||
.json ({result: constants.apiResultCodes.NO_SKILL, message: ''});
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -1,150 +0,0 @@
|
||||
var amazonHelper = require ('./helpers/amazon');
|
||||
var databaseHelper = require ('./helpers/database');
|
||||
const config = require ('./config');
|
||||
require ('isomorphic-fetch');
|
||||
var express = require ('express');
|
||||
var alexa = require ('alexa-app');
|
||||
var bodyParser = require ('body-parser');
|
||||
var MongoClient = require ('mongodb').MongoClient;
|
||||
var ObjectID = require ('mongodb').ObjectID;
|
||||
|
||||
const router = express.Router ();
|
||||
|
||||
var app = express ();
|
||||
|
||||
// ALWAYS setup the alexa app and attach it to express before anything else.
|
||||
var alexaApp = new alexa.app ('step3'); // this means we still work with one skill
|
||||
|
||||
alexaApp.express ({
|
||||
expressApp: app,
|
||||
|
||||
// verifies requests come from amazon alexa. Must be enabled for production.
|
||||
// You can disable this if you're running a dev environment and want to POST
|
||||
// things to test behavior. enabled by default.
|
||||
checkCert: false,
|
||||
|
||||
// sets up a GET route when set to true. This is handy for testing in
|
||||
// development, but not recommended for production. disabled by default
|
||||
debug: true,
|
||||
});
|
||||
|
||||
// now POST calls to /test in express will be handled by the app.request() function
|
||||
|
||||
// from here on you can setup any other express routes or middlewares as nor
|
||||
|
||||
app.set ('view engine', 'ejs');
|
||||
|
||||
var updateIntentsJSON = function () {
|
||||
databaseHelper
|
||||
.loadSkill (config.SKILL_DB_ID)
|
||||
.then (skill => {
|
||||
skill.intents.map (intent => {
|
||||
alexaApp.intent (
|
||||
intent.intentName,
|
||||
{
|
||||
slots: [],
|
||||
utterances: intent.questions,
|
||||
},
|
||||
function (request, response) {
|
||||
return response.say (intent.answer).shouldEndSession(false);
|
||||
}
|
||||
);
|
||||
});
|
||||
alexaApp.launch ((request, response) => {
|
||||
return response.say (skill.invocationAnswer).shouldEndSession(false);
|
||||
});
|
||||
})
|
||||
.catch (err => {
|
||||
console.log (err);
|
||||
alexaApp.launch ((request, response) => {
|
||||
return response.say ('Sorry, there was no skill with that name');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
router.get ('/getSkill/:id', async (req, res, next) => {
|
||||
const id = req.params.id;
|
||||
|
||||
if (id.length !== 24) {
|
||||
res.json ([]);
|
||||
} else {
|
||||
databaseHelper
|
||||
.getSkill (id)
|
||||
.then (result => {
|
||||
res.json (result);
|
||||
})
|
||||
.catch (err => {
|
||||
res.json ([]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.get ('/deleteSkill/:skillID', async (req, res, next) => {
|
||||
databaseHelper
|
||||
.deleteSkill (req.params.id)
|
||||
.then (result => {
|
||||
res.json (result);
|
||||
})
|
||||
.catch (err => {
|
||||
res.json (err);
|
||||
});
|
||||
});
|
||||
|
||||
router.post ('/updateSkill/:id', async (req, res, next) => {
|
||||
let id = req.params.id;
|
||||
let skill = req.body;
|
||||
delete skill._id;
|
||||
console.log('id = ' + id);
|
||||
if (id !== '-1') {
|
||||
amazonHelper
|
||||
.updateSkill (skill)
|
||||
.then (amazonResult => {
|
||||
console.log('amazon result : ' + amazonResult);
|
||||
if (amazonResult === 200 || amazonResult === 202) {
|
||||
//Skill uploaded, it's ok to update databaseI
|
||||
databaseHelper
|
||||
.updateSkill (id, skill)
|
||||
.then (result => {
|
||||
res.json ({result: 0, message: 'ok'});
|
||||
updateIntentsJSON ();
|
||||
})
|
||||
.catch (e => {
|
||||
res.json ({result: -1, message: 'ok'});
|
||||
});
|
||||
} else {
|
||||
res.json ({result: -1, message: 'Amazon result ' + amazonResult});
|
||||
}
|
||||
})
|
||||
.catch (e => {
|
||||
//skill upload went wrong, don't update database, send error
|
||||
res.json ({result: -1, message: e});
|
||||
});
|
||||
} else {
|
||||
//no new skills for now
|
||||
}
|
||||
});
|
||||
|
||||
app.use (function (req, res, next) {
|
||||
res.header ('Access-Control-Allow-Origin', '*');
|
||||
res.header ('Access-Control-Allow-Headers', 'Origin, Content-Type');
|
||||
res.header ('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
||||
res.header ('Access-Control-Allow-Credentials', 'true');
|
||||
next ();
|
||||
});
|
||||
|
||||
app.use (bodyParser.json ());
|
||||
app.use ('/', router);
|
||||
|
||||
MongoClient.connect (config.dbURL)
|
||||
.then (database => {
|
||||
databaseHelper.initModule (database);
|
||||
|
||||
app.listen (config.PORT, () => {
|
||||
console.log ('Express server running on port ' + config.PORT);
|
||||
updateIntentsJSON ();
|
||||
databaseHelper.loadTokens ();
|
||||
});
|
||||
})
|
||||
.catch (e => {
|
||||
console.log ('error : ' + e);
|
||||
});
|
||||
@@ -1,26 +1,20 @@
|
||||
require ('isomorphic-fetch');
|
||||
const config = require ('../config');
|
||||
const config = require ('../config/config');
|
||||
var request = require ('request');
|
||||
var databaseHelper = require ('./database');
|
||||
|
||||
var getBuildStatus = function (skillID) {
|
||||
try {
|
||||
fetch (
|
||||
`https://api.amazonalexa.com/v0/skills/${skillID}/interactionModel/locales/en-US/status`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: config.TOKEN,
|
||||
},
|
||||
}
|
||||
)
|
||||
.then (l => l.text ())
|
||||
.then (result => {
|
||||
return result;
|
||||
});
|
||||
} catch (e) {
|
||||
console.log ('err : ' + e);
|
||||
}
|
||||
fetch (
|
||||
`https://api.amazonalexa.com/v0/skills/${skillID}/interactionModel/locales/en-US/status`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: config.TOKEN,
|
||||
},
|
||||
}
|
||||
).then (result => {
|
||||
return result.text ();
|
||||
});
|
||||
};
|
||||
|
||||
var refreshTokens = function () {
|
||||
@@ -41,14 +35,27 @@ var refreshTokens = function () {
|
||||
};
|
||||
|
||||
request (options, function (error, response, body) {
|
||||
if (error) reject (error);
|
||||
parsedResponse = JSON.parse (body);
|
||||
if (parsedResponse.refresh_token)
|
||||
return databaseHelper.updateTokens (
|
||||
parsedResponse.refresh_token,
|
||||
parsedResponse.access_token,
|
||||
parsedResponse.expires_in
|
||||
);
|
||||
if (error) {
|
||||
reject (error);
|
||||
} else {
|
||||
parsedResponse = JSON.parse (body);
|
||||
if (parsedResponse.refresh_token) {
|
||||
databaseHelper
|
||||
.updateTokens (
|
||||
parsedResponse.refresh_token,
|
||||
parsedResponse.access_token,
|
||||
parsedResponse.expires_in
|
||||
)
|
||||
.then (() => {
|
||||
resolve ();
|
||||
})
|
||||
.catch (e => {
|
||||
reject (e);
|
||||
});
|
||||
} else {
|
||||
reject (body);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -56,42 +63,214 @@ var refreshTokens = function () {
|
||||
var generateInteractionModel = function (skill) {
|
||||
let result = {};
|
||||
let allIntents = [];
|
||||
let defaultIntents = [
|
||||
{
|
||||
name: 'AMAZON.CancelIntent',
|
||||
samples: [],
|
||||
},
|
||||
{
|
||||
name: 'AMAZON.HelpIntent',
|
||||
samples: [],
|
||||
},
|
||||
{
|
||||
name: 'AMAZON.StopIntent',
|
||||
samples: [],
|
||||
},
|
||||
];
|
||||
|
||||
/*
|
||||
defaultIntents.map(intent=>{
|
||||
allIntents.push(intent);
|
||||
});
|
||||
*/
|
||||
|
||||
skill.intents.map (intent => {
|
||||
allIntents.push ({name: intent.intentName, samples: intent.questions});
|
||||
});
|
||||
|
||||
//Built-In like intents (Amazon built-in don't work, probably something related to existance of dialog intent
|
||||
|
||||
allIntents.push ({
|
||||
name: 'HelpIntent',
|
||||
samples: ['Help', 'Can you help me', 'I need help'],
|
||||
slots: [],
|
||||
},
|
||||
{
|
||||
name: 'CancelIntent',
|
||||
samples: ['Cancel', 'Stop', 'Please stop'],
|
||||
slots: [],
|
||||
},
|
||||
{
|
||||
name: 'YesIntent',
|
||||
samples: [
|
||||
'Yes',
|
||||
'Yes please',
|
||||
'I would like that',
|
||||
'Yes I would like that',
|
||||
],
|
||||
slots: [],
|
||||
},
|
||||
{
|
||||
name: 'NoIntent',
|
||||
samples: ['No', 'No thank you'],
|
||||
slots: [],
|
||||
});
|
||||
|
||||
//Special intent for sending message (Dialog)
|
||||
|
||||
allIntents.push ({
|
||||
name: 'SendMessageIntent',
|
||||
samples: [
|
||||
'I would like to send a message',
|
||||
'I want to send a message',
|
||||
'Send message',
|
||||
],
|
||||
slots: [
|
||||
{
|
||||
name: 'Name',
|
||||
type: 'AMAZON.US_FIRST_NAME',
|
||||
samples: ['My name is {Name}', 'I am {Name}', '{Name}'],
|
||||
},
|
||||
{
|
||||
name: 'Email',
|
||||
type: 'EmailSlot',
|
||||
samples: ['My email is {Email}', '{Email}'],
|
||||
},
|
||||
{
|
||||
name: 'Message',
|
||||
type: 'MessageSlot',
|
||||
samples: ['{Message}'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
let customSlotTypes = [
|
||||
{
|
||||
name: 'EmailSlot',
|
||||
values: [
|
||||
{
|
||||
id: null,
|
||||
name: {
|
||||
value: 'bla@bla.bla',
|
||||
synonyms: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: null,
|
||||
name: {
|
||||
value: 'bla.bla@bla.bla.bla',
|
||||
synonyms: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: null,
|
||||
name: {
|
||||
value: 'bla_bla@bla.bla',
|
||||
synonyms: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'MessageSlot',
|
||||
values: [
|
||||
{
|
||||
id: null,
|
||||
name: {
|
||||
value: 'Quick brown fox jumps over lazy dog',
|
||||
synonyms: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: null,
|
||||
name: {
|
||||
value: 'Quick brown fox jumps over lazy dog. Quick brown fox jumps over lazy dog.',
|
||||
synonyms: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: null,
|
||||
name: {
|
||||
value: 'Quick brown fox jumps over lazy dog. Quick brown fox jumps over lazy dog. Quick brown fox jumps over lazy dog.',
|
||||
synonyms: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
let dialogPrompts = [
|
||||
{
|
||||
id: 'Elicit.Intent-SendMessageIntent.IntentSlot-Name',
|
||||
variations: [
|
||||
{
|
||||
type: 'PlainText',
|
||||
value: 'What is your name ?',
|
||||
},
|
||||
{
|
||||
type: 'PlainText',
|
||||
value: 'Tell me your name',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'Elicit.Intent-SendMessageIntent.IntentSlot-Email',
|
||||
variations: [
|
||||
{
|
||||
type: 'PlainText',
|
||||
value: 'What is your email ?',
|
||||
},
|
||||
{
|
||||
type: 'PlainText',
|
||||
value: 'Tell me your email',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'Elicit.Intent-SendMessageIntent.IntentSlot-Message',
|
||||
variations: [
|
||||
{
|
||||
type: 'PlainText',
|
||||
value: 'What is your message',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
let dialogIntents = [
|
||||
{
|
||||
name: 'SendMessageIntent',
|
||||
confirmationRequired: false,
|
||||
prompts: {},
|
||||
slots: [
|
||||
{
|
||||
name: 'Name',
|
||||
type: 'AMAZON.US_FIRST_NAME',
|
||||
elicitationRequired: true,
|
||||
confirmationRequired: false,
|
||||
prompts: {
|
||||
elicitation: 'Elicit.Intent-SendMessageIntent.IntentSlot-Name',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Email',
|
||||
type: 'EmailSlot',
|
||||
elicitationRequired: true,
|
||||
confirmationRequired: false,
|
||||
prompts: {
|
||||
elicitation: 'Elicit.Intent-SendMessageIntent.IntentSlot-Email',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Message',
|
||||
type: 'MessageSlot',
|
||||
elicitationRequired: true,
|
||||
confirmationRequired: false,
|
||||
prompts: {
|
||||
elicitation: 'Elicit.Intent-SendMessageIntent.IntentSlot-Message',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
result.interactionModel = {};
|
||||
|
||||
result.interactionModel.languageModel = {
|
||||
invocationName: skill.invocationName,
|
||||
types: customSlotTypes,
|
||||
intents: allIntents,
|
||||
};
|
||||
|
||||
result.interactionModel.prompts = dialogPrompts;
|
||||
result.interactionModel.dialog = {};
|
||||
result.interactionModel.dialog.intents = dialogIntents;
|
||||
|
||||
return JSON.stringify (result);
|
||||
};
|
||||
|
||||
var uploadSkill = function (skill) {
|
||||
let generatedInteractionModel = generateInteractionModel (skill);
|
||||
return fetch (
|
||||
`https://api.amazonalexa.com/v0/skills/${skill.skillID}/interactionModel/locales/en-US`,
|
||||
{
|
||||
@@ -99,7 +278,7 @@ var uploadSkill = function (skill) {
|
||||
headers: {
|
||||
Authorization: config.TOKEN,
|
||||
},
|
||||
body: generateInteractionModel (skill),
|
||||
body: generatedInteractionModel,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const config = require ('../config');
|
||||
const config = require ('../config/config');
|
||||
var ObjectID = require ('mongodb').ObjectID;
|
||||
|
||||
var db = null;
|
||||
@@ -43,16 +43,19 @@ module.exports = {
|
||||
db
|
||||
.collection ('token_list')
|
||||
.update ({id: 1}, newTokenDocument, {upsert: true}, (err, result) => {
|
||||
if (err) reject (err);
|
||||
config.REFRESH_TOKEN = refresh_token;
|
||||
config.TOKEN = access_token;
|
||||
config.TOKEN_EXPIRES_IN = newTokenDocument.expires_in;
|
||||
resolve ();
|
||||
if (err) {
|
||||
reject (err)
|
||||
}else{
|
||||
config.REFRESH_TOKEN = refresh_token;
|
||||
config.TOKEN = access_token;
|
||||
config.TOKEN_EXPIRES_IN = newTokenDocument.expires_in;
|
||||
resolve ();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
loadSkill: function (skillDbID) {
|
||||
getSkill: function (skillDbID) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
db
|
||||
.collection ('skill_list')
|
||||
@@ -71,11 +74,10 @@ module.exports = {
|
||||
db
|
||||
.collection ('skill_list')
|
||||
.update ({_id: ObjectID (id)}, skill, {upsert: true}, (err, result) => {
|
||||
if (JSON.parse (result).nModified === 1) {
|
||||
//database update ok
|
||||
resolve ();
|
||||
} else {
|
||||
reject ();
|
||||
if (err){
|
||||
reject();
|
||||
}else{
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -86,21 +88,12 @@ module.exports = {
|
||||
db
|
||||
.collection ('skill_list')
|
||||
.remove ({_id: ObjectID (id)}, (err, result) => {
|
||||
if (err) reject (err);
|
||||
resolve (result);
|
||||
if (err){
|
||||
reject (err);
|
||||
}else{
|
||||
resolve (result);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getSkill: function (id) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
db
|
||||
.collection ('skill_list')
|
||||
.find ({_id: ObjectID (id)})
|
||||
.toArray ((err, result) => {
|
||||
if (err) reject (err);
|
||||
resolve (result);
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
75
backend/helpers/email.js
Normal file
75
backend/helpers/email.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const nodemailer = require ('nodemailer');
|
||||
const emailConfig = require('../config/email');
|
||||
|
||||
module.exports = {
|
||||
transformEmailFromAlexaResponse: function (email) {
|
||||
//email from alexa response will contain words instead of symbols, like :
|
||||
//at = @
|
||||
//underscore = _
|
||||
//dash = -
|
||||
//dot = .
|
||||
//TODO: This list should be longer
|
||||
let transformedEmail = email
|
||||
.replace (/\s/g, '') //remove all spaces
|
||||
.replace (/at/gi, '@')
|
||||
.replace (/underscore/gi, '_')
|
||||
.replace (/dash/gi, '-')
|
||||
.replace (/dot/gi, '.');
|
||||
|
||||
return transformedEmail;
|
||||
},
|
||||
|
||||
isEmailValid: function (email) {
|
||||
console.log ('Email to validate : ' + email);
|
||||
let validEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
|
||||
return validEmailRegex.test (email);
|
||||
},
|
||||
|
||||
sendEmail: function (name, fromEmail, message, toEmail) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
fromEmail = this.transformEmailFromAlexaResponse(fromEmail);
|
||||
let messageBody =
|
||||
'Hello. User left you a message on Saburly service using Alexa skill. \r\nMessage : ' +
|
||||
message +
|
||||
'\r\nName : ' +
|
||||
name +
|
||||
'\r\nEmail : ' +
|
||||
fromEmail +
|
||||
'\r\nYour Saburly team';
|
||||
|
||||
let messageBodyHTML =
|
||||
'<p>Hello. User left you a message on Saburly service using Alexa skill.</p><br/><b>Message : </b><br/><p>' +
|
||||
message +
|
||||
'</p><br/><b>Name : </b>' +
|
||||
name +
|
||||
'<br/><b>Email : </b>' +
|
||||
fromEmail +
|
||||
'<br/><br/><b>Your Saburly team</b>';
|
||||
|
||||
let transporter = nodemailer.createTransport ({
|
||||
host: emailConfig.SMTP_HOST,
|
||||
port: emailConfig.PORT,
|
||||
secure: emailConfig.SECURE,
|
||||
auth: emailConfig.AUTH,
|
||||
});
|
||||
|
||||
var mailOptions = {
|
||||
from: emailConfig.FROM_EMAIL,
|
||||
replyTo: fromEmail,
|
||||
to: toEmail,
|
||||
subject: emailConfig.SUBJECT,
|
||||
text: messageBody,
|
||||
html: messageBodyHTML,
|
||||
};
|
||||
|
||||
transporter.sendMail (mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
reject (error);
|
||||
} else {
|
||||
resolve (info);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
100
backend/helpers/skillValidator.js
Normal file
100
backend/helpers/skillValidator.js
Normal file
@@ -0,0 +1,100 @@
|
||||
const constants = require ('../config/constants');
|
||||
|
||||
validateEmail = function (email) {
|
||||
if (email.length > constants.stringConstraints.EMAIL_MAX_LENGTH) return false;
|
||||
let validEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return validEmailRegex.test (email);
|
||||
};
|
||||
|
||||
validateIntentName = function (intentName) {
|
||||
if (
|
||||
intentName.length < constants.stringConstraints.INTENT_NAME_MIN_LENGTH ||
|
||||
intentName.length > constants.stringConstraints.INTENT_NAME_MAX_LENGTH
|
||||
)
|
||||
return false;
|
||||
let validIntentNameRegex = /^[a-z]*$/i;
|
||||
return validIntentNameRegex.test (intentName);
|
||||
};
|
||||
|
||||
validateQuestion = function (question) {
|
||||
if (
|
||||
question.length < constants.stringConstraints.QUESTION_MIN_LENGTH ||
|
||||
question.length > constants.stringConstraints.QUESTION_MAX_LENGTH
|
||||
)
|
||||
return false;
|
||||
let validQuestionNameRegex = /^[a-z,.' ]*$/i;
|
||||
return validQuestionNameRegex.test (question);
|
||||
};
|
||||
|
||||
validateAnswer = function (answer) {
|
||||
if (
|
||||
answer.length < constants.stringConstraints.ANSWER_MIN_LENGTH ||
|
||||
answer.length > constants.stringConstraints.ANSWER_MAX_LENGTH
|
||||
)
|
||||
return false;
|
||||
let validAnswerRegex = /^[a-z,.' ]*$/i;
|
||||
return validAnswerRegex.test (answer);
|
||||
};
|
||||
|
||||
validateInvocationName = function (invocationName) {
|
||||
if (
|
||||
invocationName.length < constants.stringConstraints.INVOCATION_NAME_MIN_LENGTH ||
|
||||
invocationName.length > constants.stringConstraints.INVOCATION_NAME_MAX_LENGTH
|
||||
)
|
||||
return false;
|
||||
let validInvocationNameRegex = /^[a-z,.' ]*$/i;
|
||||
return validInvocationNameRegex.test (invocationName);
|
||||
};
|
||||
|
||||
validateInvocationAnswer = function (invocationAnswer) {
|
||||
if (invocationAnswer.length > constants.stringConstraints.INVOCATION_ANSWER_MAX_LENGTH)
|
||||
return false;
|
||||
let validInvocationAnswerRegex = /^[a-z,.' ]*$/i;
|
||||
return validInvocationAnswerRegex.test (invocationAnswer);
|
||||
};
|
||||
|
||||
validateIntentExplanation = function (explanation) {
|
||||
if (explanation.length > constants.stringConstraints.INTENT_EXPLANATION_MAX_LENGTH)
|
||||
return false;
|
||||
let validExplanationRegex = /^[a-z,.' ]*$/i;
|
||||
return validExplanationRegex.test (explanation);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateSkill: function (skill) {
|
||||
try {
|
||||
if (
|
||||
!validateEmail (skill.contactEmail) ||
|
||||
!validateInvocationName (skill.invocationName) ||
|
||||
!validateInvocationAnswer (skill.invocationAnswer)
|
||||
)
|
||||
return false;
|
||||
|
||||
for (let i = 0; i < skill.intents.length; i++) {
|
||||
if (!validateIntentName (skill.intents[i].intentName)) return false;
|
||||
if (!validateAnswer (skill.intents[i].answer)) return false;
|
||||
|
||||
for (let j = 0; j < skill.intents.length; j++) {
|
||||
if (i === j) continue;
|
||||
if (skill.intents[i].intentName === skill.intents[j].intentName)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let j = 0; j < skill.intents[i].questions.length; j++) {
|
||||
if (!validateQuestion (skill.intents[i].questions[j])) return false;
|
||||
|
||||
for (let k = 0; k < skill.intents[i].questions.length; k++) {
|
||||
if (j === k) continue;
|
||||
if (skill.intents[i].questions[j] === skill.intents[i].questions[k])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.log ('Error : ' + e);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
7
backend/middleware/index.js
Normal file
7
backend/middleware/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = function (req, res, next) {
|
||||
res.header ('Access-Control-Allow-Origin', '*');
|
||||
res.header ('Access-Control-Allow-Headers', 'Origin, Content-Type');
|
||||
res.header ('Access-Control-Allow-Methods', 'GET, POST, PUT');
|
||||
res.header ('Access-Control-Allow-Credentials', 'true');
|
||||
next ();
|
||||
};
|
||||
231
backend/models/alexa.js
Normal file
231
backend/models/alexa.js
Normal file
@@ -0,0 +1,231 @@
|
||||
var Alexa = require ('alexa-sdk');
|
||||
const config = require ('../config/config');
|
||||
var databaseHelper = require ('../helpers/database');
|
||||
var emailHelper = require ('../helpers/email');
|
||||
const constants = require ('../config/constants');
|
||||
|
||||
var handlers = {};
|
||||
var destinationEmail;
|
||||
|
||||
module.exports = {
|
||||
run: function (req, res) {
|
||||
// Build the context manually, because Amazon Lambda is missing
|
||||
var context = {
|
||||
succeed: function (result) {
|
||||
res.json (result);
|
||||
},
|
||||
fail: function (error) {
|
||||
console.log (error);
|
||||
//We could send error json from here
|
||||
},
|
||||
};
|
||||
|
||||
var alexa = Alexa.handler (req.body, context);
|
||||
alexa.appId = config.SKILL_ID;
|
||||
alexa.registerHandlers (handlers);
|
||||
alexa.execute ();
|
||||
},
|
||||
updateModel: function () {
|
||||
//Get info from database, and store it for faster response on intent
|
||||
databaseHelper
|
||||
.getSkill (config.SKILL_DB_ID)
|
||||
.then (activeSkill => {
|
||||
handlers = {};
|
||||
destinationEmail = activeSkill.contactEmail;
|
||||
|
||||
let listOfPossibleQuestions = '';
|
||||
activeSkill.intents.forEach (intent => {
|
||||
if (intent.questions.length > 0 && intent.intentExplanation) {
|
||||
listOfPossibleQuestions +=
|
||||
intent.intentExplanation +
|
||||
intent.questions[0] +
|
||||
'<break time="' +
|
||||
constants.voiceResponseTimings.PAUSE_BETWEEN_QUESTIONS +
|
||||
'ms"/>';
|
||||
}
|
||||
});
|
||||
listOfPossibleQuestions += 'If you dont know what to do, just say help or stop';
|
||||
|
||||
//Handler for launch requestconsole.log()
|
||||
handlers = {
|
||||
LaunchRequest: function () {
|
||||
this.response
|
||||
.speak (
|
||||
activeSkill.invocationAnswer +
|
||||
'<break time="' +
|
||||
constants.voiceResponseTimings.PAUSE_AFTER_WELCOME_MESSAGE +
|
||||
'ms"/>' +
|
||||
'Would you like to hear list of questions that you can ask me'
|
||||
)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||
this.attributes['LaunchRequestYesNo'] = true;
|
||||
this.emit (':responseReady');
|
||||
},
|
||||
};
|
||||
|
||||
//Handlers for user defined questions
|
||||
activeSkill.intents.map (intent => {
|
||||
handlers[intent.intentName] = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
this.response
|
||||
.speak (intent.answer)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||
this.emit (':responseReady');
|
||||
};
|
||||
});
|
||||
|
||||
//Handler for sending message
|
||||
handlers.SendMessageIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
|
||||
let intent = this.event.request.intent;
|
||||
|
||||
console.log ('Dialog state : ' + this.event.request.dialogState);
|
||||
console.log (intent);
|
||||
//STARTED, IN_PROGRESS
|
||||
|
||||
if (!intent.slots.Name.value) {
|
||||
//Name not defined yet, ask user for name
|
||||
const slotToElicit = 'Name';
|
||||
const speechOutput = 'What is your name';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
} else if (!intent.slots.Email.value) {
|
||||
//Name not defined yet, ask user for email
|
||||
const slotToElicit = 'Email';
|
||||
const speechOutput =
|
||||
'Ok ' + intent.slots.Name.value + '. What is your email';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
} else if (!intent.slots.Message.value) {
|
||||
intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse (
|
||||
intent.slots.Email.value
|
||||
);
|
||||
if (!emailHelper.isEmailValid (intent.slots.Email.value)) {
|
||||
//Email is not valid, ask again
|
||||
const slotToElicit = 'Email';
|
||||
const speechOutput =
|
||||
'Sorry, that was not valid email. What is your email';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
} else {
|
||||
//Email is valid
|
||||
const slotToElicit = 'Message';
|
||||
const speechOutput = 'Great. What is your message';
|
||||
const repromptSpeech = speechOutput;
|
||||
this.emit (
|
||||
':elicitSlot',
|
||||
slotToElicit,
|
||||
speechOutput,
|
||||
repromptSpeech
|
||||
);
|
||||
}
|
||||
} else {
|
||||
//all slots are filled
|
||||
console.log ('Name : ' + intent.slots.Name.value);
|
||||
console.log ('Email : ' + intent.slots.Email.value);
|
||||
console.log ('Message : ' + intent.slots.Message.value);
|
||||
emailHelper
|
||||
.sendEmail (
|
||||
intent.slots.Name.value,
|
||||
intent.slots.Email.value,
|
||||
intent.slots.Message.value,
|
||||
destinationEmail
|
||||
)
|
||||
.then (info => {
|
||||
console.log (info);
|
||||
this.response.speak (
|
||||
'Ok. Message sent. Someone will contact you ASAP'
|
||||
);
|
||||
this.emit (':responseReady');
|
||||
})
|
||||
.catch (error => {
|
||||
console.log (error);
|
||||
this.response.speak (
|
||||
'Sorry, there was a problem with sending message.'
|
||||
);
|
||||
this.emit (':responseReady');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//Built-In intents
|
||||
|
||||
handlers.CancelIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
this.response.speak ('Thank you for using Saburly');
|
||||
this.emit (':responseReady');
|
||||
};
|
||||
|
||||
handlers.HelpIntent = function () {
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
}
|
||||
this.response
|
||||
.speak (listOfPossibleQuestions)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE); //Phrase from listen doesn't work !!!
|
||||
this.emit (':responseReady');
|
||||
};
|
||||
|
||||
handlers.YesIntent = function(){
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
this.emit('HelpIntent');
|
||||
}else{
|
||||
this.response.speak(constants.voiceResponseStrings.DIDNT_ASK_ANYTHING).listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit(':responseReady');
|
||||
}
|
||||
}
|
||||
|
||||
handlers.NoIntent = function (){
|
||||
if (this.attributes['LaunchRequestYesNo']){
|
||||
this.attributes['LaunchRequestYesNo'] = false;
|
||||
this.response.speak('').listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit(':responseReady');
|
||||
}else{
|
||||
this.response.speak(constants.voiceResponseStrings.DIDNT_ASK_ANYTHING).listen(constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
this.emit(':responseReady');
|
||||
}
|
||||
}
|
||||
|
||||
//Default handler for unknown question
|
||||
|
||||
handlers.Unhandled = function () {
|
||||
this.response
|
||||
.speak (constants.voiceResponseStrings.QUESTION_NOT_FOUND)
|
||||
.listen (constants.voiceResponseStrings.GENERIC_CONTINUE);
|
||||
};
|
||||
|
||||
//Session handlers
|
||||
|
||||
handlers.SessionEndedRequest = function () {
|
||||
//We don't care for now
|
||||
};
|
||||
})
|
||||
.catch (e => {
|
||||
//Something is wrong, skill is not ready, use catch-all intent to inform user
|
||||
console.log ('Error. Skill doesnt exist');
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -4,12 +4,13 @@
|
||||
"description": "",
|
||||
"main": "test.js",
|
||||
"dependencies": {
|
||||
"alexa-app": "4.2.0",
|
||||
"alexa-sdk": "^1.0.25",
|
||||
"body-parser": "^1.13.1",
|
||||
"ejs": "^2.5.7",
|
||||
"express": "^4.13.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"mongodb": "^2.2.33",
|
||||
"nodemailer": "^4.4.1",
|
||||
"request": "^2.83.0"
|
||||
},
|
||||
"author": "Matt Kruse <github@mattkruse.com> (http://mattkruse.com/)",
|
||||
|
||||
28
backend/server.js
Normal file
28
backend/server.js
Normal file
@@ -0,0 +1,28 @@
|
||||
var databaseHelper = require ('./helpers/database');
|
||||
const config = require ('./config/config');
|
||||
var express = require ('express');
|
||||
var alexa = require ('./models/alexa');
|
||||
|
||||
var MongoClient = require ('mongodb').MongoClient;
|
||||
var ObjectID = require ('mongodb').ObjectID;
|
||||
|
||||
const router = express.Router ();
|
||||
var app = express ();
|
||||
|
||||
app.set ('view engine', 'ejs'); // Should be removed
|
||||
app.use (require ('./middleware')); //common middleware for all requests
|
||||
app.use (require ('./controllers')); //all routes
|
||||
|
||||
MongoClient.connect (config.DB_URL)
|
||||
.then (database => {
|
||||
databaseHelper.initModule (database);
|
||||
|
||||
app.listen (config.PORT, () => {
|
||||
console.log ('Express server running on port ' + config.PORT);
|
||||
alexa.updateModel ();
|
||||
databaseHelper.loadTokens ();
|
||||
});
|
||||
})
|
||||
.catch (e => {
|
||||
console.log ('error : ' + e);
|
||||
});
|
||||
@@ -1,82 +0,0 @@
|
||||
To obtain new Auth Code :
|
||||
|
||||
https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.c748ca56ded04a95b236979898585ff7&scope=alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test&response_type=code&redirect_uri=https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO
|
||||
|
||||
Response URL (Decoded) :
|
||||
|
||||
https://layla.amazon.com/api/skill/link/M2ODJY6EXOY6KO?code=ANCgZUfEFdlRRkpSNFuA&scope=alexa::ask:skills:readwrite alexa::ask:models:readwrite alexa::ask:skills:test
|
||||
|
||||
Code : ANCgZUfEFdlRRkpSNFuA
|
||||
|
||||
=======================================
|
||||
|
||||
Now to get Access Token :
|
||||
|
||||
Send a POST request to https://api.amazon.com/auth/o2/token with the following parameters
|
||||
|
||||
- HTTP Header Parameters
|
||||
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
- HTTP Body Parameters
|
||||
|
||||
grant_type: authorization_code
|
||||
code: The authorization code that was returned in the response.
|
||||
client_id: The product’s client ID. To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
client_secret: The product’s client secret. To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
redirect_uri: One of the return URIs that you added to your app’s security profile when signing up.
|
||||
|
||||
Response :
|
||||
|
||||
{
|
||||
"access_token": "Atza|IwEBIBe6gDqrrowEEav6N-_6s4NztYeP3oG8PGWmu8ZiZw6lbOh3wNla3TK6pY-VEpT1d8an-dVf_n3kXJzVFsNo_4xBfZyFHGoCTDTFjs3yBRul4PVdBOhwwiH3-sgRLcUofZbe2oE06GmTcbfYtaStfXpQI5dfpldfnsJg_CvhSA6AHb_snJT3F6lyXzbV076d_3cYUMJxFldJGnYcviNHHxjjmuQTD06hhGzCbAxxe9eBmkuopRsNfyedLT2UlKP_ublah9CUGA3AdIX_3Iuke82jMwGnNl9gv7pbaDNEjAbj7IQSl3B08uuREtJq-oTBOjALNXRvFxTJmQjZwXNf9eHC7fSHJDdEPdZQU0AcffRQObAyAkUuL6Jv39OHzhb3Q64-zzoyODqnJyLP5SQZ2JVF53Kc_cTBqjIc9pXljqe7yEVk6JDs7q1zKbBibx_AQm57TO79IzWyLBzBMlYL5HdTsqEfRzLeDw2tws-hGMgkx2HWfdbYnmf5Qb4SyIhzvmmdfPLg3MVKTxjIBu1rx0xf3n0PLZP1EO6jsJPoMRPg77Gm4oit5Zp6s37ek3A3Vxh-ntoASpkrkxGTG9kVtRNt",
|
||||
"refresh_token": "Atzr|IwEBICA3kDhfSJxlwvnQp9AD1o115AC_KBbFd5GBg8oN_QHWn2or5xFQ09BruuK6a07tGHtTt_9q2Y21mnOMH4RDtYXTVG9ADgLE6mHWKZFxYVwt3kHMiUJdY5lJcsOtWLoblrS-bJ0BEXXK5nVDt_bSI5IB7NUf-9QVZxhovRH_ANSxdTjJT0_rMIAZY3WEj68FEap49q_pg72BhnxHVZD2TC3zvX96_DN65HE5SoSgT7OiMAeiJewB_SyemW_HxBwaB-_X-G1ifOtnrzZ4gXTpOrEUlHI2YPuvRMBMtmz1h-nXDZYv3vwU3RA57Qj_ZNVcScj8_RXf2xq8w48v0PzZFXYBSalfnqPq6eUvSSbAJUp6bB8y596JlvR5dFQe_Z--X0Gkfo85IcyrI9D44vK9sJhrGhCVi2FDDa8pHczmNSen99JYZvDif-zpYzgbcymAkOV0gC7JvYMxlZfETT3NTBy7eVA7fJI1SZaeA_qW49xRcBkZBu5gkqTpeGWUU1cGr2aXRVVmXGM22NfV5E7KzvEBsCeHml_tCfxZeKY8Msd8hJb0Cd59u-_hsuc8oNjsOpIdFF976dY3uTmAgHWpG2PH",
|
||||
"token_type": "bearer",
|
||||
"expires_in": 3600
|
||||
}
|
||||
|
||||
================================
|
||||
|
||||
Now to get new Access token using refresh token :
|
||||
|
||||
Send a POST request to https://api.amazon.com/auth/o2/token with the following parameters:
|
||||
|
||||
- HTTP Header Parameters
|
||||
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
- HTTP Body Parameters
|
||||
|
||||
grant_type: refresh_token
|
||||
refresh_token: The URL-encoded refresh token returned with the last request for a new access token.
|
||||
client_id: To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
client_secret: The website’s client secret. To access this information, navigate to Amazon’s Developer Console. After you’ve logged in, click Get Started > under Alexa Voice Service, then click Edit next to a registered product (or create a new one). From the left navigation select Security Profile. This page contains both Client ID and Client Secret for your product.
|
||||
|
||||
Response :
|
||||
|
||||
{
|
||||
"access_token": "Atza|IwEBILtBe3hrHovrMx7Oivng-RB2EKzvCm_epXJE2HXPMQzXTFqK10Zrqt-Z8paeRoLQBqbLCmqWvcr5RTNgw9qjtfzOTsOrXC1VKqKmxpqHTrJyn2TLGsCzFjBDfADNjCyufWTf2ZlsSzjxW2GiqCHlwoPSd9pFrLavtRThrm1J-5KvnFrj-yD-tYTSwrgX5W5p2SrjQxoE3aP5b96z6p8GvCL9lM1pddafAxkHb22A3IzR-pYGmEijb4ksRuaIf4WCNwssWV6GBIB2oJA5CU-Dtd2mOZZ5-dYpSSeCHyGumTYecTxxMVSdiVjCqB8WT6AtvvutWFQQoldHjJmIwBsTZP-iQcl-UyajOZJ03GqRUym5Hp-49uByzVG-MfR_Z5qVmYjjsLQEOLCY9kPVnmRGnOTj6YPjrHXibd6P8TQOMh4VTcgFpg-afKKABP6EeDwok1t2ivuYh5OJju-B1A6gzhMi4vQJYKq107e0QMYBBhrf_OqCgMbfnQZ8j40qocVGID5YWv8uk5wKyI61LrbzrTltmzxzNemzqbSBzwAlfNS6GW-jVjg8svsi1lb_EVRbhyOoWJWX3mEd-5GDYyUcyInleiAR0aIHVP94pZxqdiCamA",
|
||||
"refresh_token": "Atzr|IwEBICA3kDhfSJxlwvnQp9AD1o115AC_KBbFd5GBg8oN_QHWn2or5xFQ09BruuK6a07tGHtTt_9q2Y21mnOMH4RDtYXTVG9ADgLE6mHWKZFxYVwt3kHMiUJdY5lJcsOtWLoblrS-bJ0BEXXK5nVDt_bSI5IB7NUf-9QVZxhovRH_ANSxdTjJT0_rMIAZY3WEj68FEap49q_pg72BhnxHVZD2TC3zvX96_DN65HE5SoSgT7OiMAeiJewB_SyemW_HxBwaB-_X-G1ifOtnrzZ4gXTpOrEUlHI2YPuvRMBMtmz1h-nXDZYv3vwU3RA57Qj_ZNVcScj8_RXf2xq8w48v0PzZFXYBSalfnqPq6eUvSSbAJUp6bB8y596JlvR5dFQe_Z--X0Gkfo85IcyrI9D44vK9sJhrGhCVi2FDDa8pHczmNSen99JYZvDif-zpYzgbcymAkOV0gC7JvYMxlZfETT3NTBy7eVA7fJI1SZaeA_qW49xRcBkZBu5gkqTpeGWUU1cGr2aXRVVmXGM22NfV5E7KzvEBsCeHml_tCfxZeKY8Msd8hJb0Cd59u-_hsuc8oNjsOpIdFF976dY3uTmAgHWpG2PH",
|
||||
"token_type": "bearer",
|
||||
"expires_in": 3600
|
||||
}
|
||||
|
||||
=======================
|
||||
=======================
|
||||
|
||||
Prerequests for step 3 :
|
||||
|
||||
Database (tellall) with collection (skill_list)
|
||||
Insert dummy skill with : db.skill_list.insert({"skillID" : "amzn1.ask.skill.efbf0564-a732-4ba9-958f-57939138adae", "intents" : [ { "intentName" : "GetFirstQuestion", "questions" : [ "tell me something about projects", "tell me all about projects" ], "answer" : "blablabla bla bla" }, { "intentName" : "GetThirdQuestion", "questions" : [ "Give me third question" ], "answer" : "This is answer to the third question" } ], "invocationName" : "Saburly", "invocationAnswer" : "We are Saburly team one" })
|
||||
obtain _id and change in web/src/App.js, and also skill_db_id in backend/config.js
|
||||
enter web/ dir and run "npm run build"
|
||||
|
||||
Database (tellall) with collection (token_list)
|
||||
Insert tokens with : db.token_list.insert({"id" : 1, "refresh_token" : "...", "access_token" : "...", "expires_in" : 1515173601.754 })
|
||||
(Change refresh_token and access_token dots with real ones)
|
||||
|
||||
Set skill_id, client_id and client_secret to appropriate values in backend/config.js
|
||||
Set base_url to "tellall.saburly.com" in web/src/config.
|
||||
|
||||
Start backend service from backend/ running "node express.js"
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
"watch-css": "nodemon -e scss -x \"npm run watch-css-mine\"",
|
||||
"start-js": "react-scripts start",
|
||||
"start": "npm-run-all -p watch-css start-js",
|
||||
"build": "react-scripts build",
|
||||
"react-build" : "react-scripts build",
|
||||
"build": "npm-run-all -p build-css react-build",
|
||||
"test": "react-scripts test --env=jsdom",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
|
||||
451
web/src/App.js
451
web/src/App.js
@@ -1,181 +1,360 @@
|
||||
import React, { Component } from 'react';
|
||||
import React, {Component} from 'react';
|
||||
import './css/App.css';
|
||||
import './css/popup.css';
|
||||
import IntentList from './components/IntentList';
|
||||
import IntentDetails from './components/IntentDetails';
|
||||
import LaunchRequest from './components/LaunchRequest';
|
||||
import Contact from './components/Contact';
|
||||
import Popup from 'react-popup';
|
||||
|
||||
import {getSkill, updateSkill} from './lib/api'
|
||||
import {getSkill, updateSkill} from './lib/api';
|
||||
import {isEmailValid} from './lib/helpers';
|
||||
import {
|
||||
NEW_INTENT_SELECTED_INDEX,
|
||||
LAUNCH_REQUEST_SELECTED_INDEX,
|
||||
CONTACT_SELECTED_INDEX,
|
||||
RESULT_CODES,
|
||||
INVOCATION_NAME_MIN_LENGTH,
|
||||
INTENT_NAME_MIN_LENGTH,
|
||||
QUESTION_MIN_LENGTH,
|
||||
ANSWER_MIN_LENGTH,
|
||||
} from './config/constants';
|
||||
|
||||
class App extends Component {
|
||||
constructor (props) {
|
||||
super (props);
|
||||
|
||||
constructor(props){
|
||||
super(props);
|
||||
this.state = {
|
||||
_id: '5a232fb86ce046c749739455',
|
||||
skillID: '',
|
||||
skillName: '',
|
||||
invocationName: 'Saburly',
|
||||
invocationAnswer: 'We are saburly',
|
||||
allIntents: [],
|
||||
selectedIntent: {
|
||||
intentName: '',
|
||||
intentExplanation: '',
|
||||
questions: [''],
|
||||
answer: '',
|
||||
},
|
||||
selectedIndex: NEW_INTENT_SELECTED_INDEX,
|
||||
contactEmail: '',
|
||||
waiting: false,
|
||||
};
|
||||
|
||||
this.state={_id:'5a232fb86ce046c749739455',
|
||||
skillID:'',
|
||||
skillName:'',
|
||||
invocationName:'Saburly',
|
||||
invocationAnswer:'We are saburly',
|
||||
allIntents:[],
|
||||
selectedIntent: {intentName:'',questions:[''],answer:''},
|
||||
selectedIndex:-1,
|
||||
launchRequest:false,
|
||||
waiting: false
|
||||
};
|
||||
getSkill (this.state._id).then (l => l.json ()).then (result => {
|
||||
if (result === undefined) return;
|
||||
this.setState ({
|
||||
skillID: result.skillID,
|
||||
skillName: result.skillName,
|
||||
invocationName: result.invocationName,
|
||||
invocationAnswer: result.invocationAnswer,
|
||||
allIntents: result.intents,
|
||||
contactEmail: result.contactEmail,
|
||||
});
|
||||
});
|
||||
|
||||
getSkill(this.state._id).then(l=> l.text()).then(result=>{
|
||||
let jResult = JSON.parse(result)[0];
|
||||
if (jResult===undefined) return;
|
||||
this.setState({ skillID:jResult.skillID,skillName:jResult.skillName, invocationName: jResult.invocationName,
|
||||
invocationAnswer: jResult.invocationAnswer,
|
||||
allIntents: jResult.intents})
|
||||
})
|
||||
|
||||
this.handleIntentClick = this.handleIntentClick.bind(this);
|
||||
this.handleLaunchRequestClick = this.handleLaunchRequestClick.bind(this);
|
||||
this.handleDeleteIntentClick = this.handleDeleteIntentClick.bind(this);
|
||||
this.handleSaveIntentClick = this.handleSaveIntentClick.bind(this);
|
||||
this.handleAddIntentClick = this.handleAddIntentClick.bind(this);
|
||||
this.handleSaveLaunchRequestClick = this.handleSaveLaunchRequestClick.bind(this);
|
||||
this.createSkill = this.createSkill.bind(this);
|
||||
this.sendSkill = this.sendSkill.bind(this);
|
||||
this.handleIntentClick = this.handleIntentClick.bind (this);
|
||||
this.handleLaunchRequestClick = this.handleLaunchRequestClick.bind (this);
|
||||
this.handleDeleteIntentClick = this.handleDeleteIntentClick.bind (this);
|
||||
this.handleSaveIntentClick = this.handleSaveIntentClick.bind (this);
|
||||
this.handleAddIntentClick = this.handleAddIntentClick.bind (this);
|
||||
this.handleSaveLaunchRequestClick = this.handleSaveLaunchRequestClick.bind (
|
||||
this
|
||||
);
|
||||
this.createSkill = this.createSkill.bind (this);
|
||||
this.sendSkill = this.sendSkill.bind (this);
|
||||
this.handleContactClick = this.handleContactClick.bind (this);
|
||||
this.handleSaveEmailClick = this.handleSaveEmailClick.bind (this);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
if(this.state.launchRequest){
|
||||
return (
|
||||
<div className="App">
|
||||
<Popup/>
|
||||
<div className="App-header">
|
||||
<h1> Tell All </h1>
|
||||
</div>
|
||||
<IntentList allIntents={this.state.allIntents}
|
||||
onLaunchRequestClick={this.handleLaunchRequestClick}
|
||||
onIntentClick={this.handleIntentClick}
|
||||
onAddIntentClick={this.handleAddIntentClick}
|
||||
selectedIndex={this.state.selectedIndex}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentList>
|
||||
<LaunchRequest invocationName={this.state.invocationName}
|
||||
invocationAnswer={this.state.invocationAnswer}
|
||||
onSaveClick={this.handleSaveLaunchRequestClick}
|
||||
waiting={this.state.waiting}>
|
||||
</LaunchRequest>
|
||||
</div>
|
||||
);
|
||||
}else{
|
||||
return (
|
||||
<div className="App">
|
||||
<Popup/>
|
||||
<div className="App-header">
|
||||
<h1> Tell All </h1>
|
||||
</div>
|
||||
<IntentList allIntents={this.state.allIntents}
|
||||
onLaunchRequestClick={this.handleLaunchRequestClick}
|
||||
onIntentClick={this.handleIntentClick}
|
||||
onAddIntentClick={this.handleAddIntentClick}
|
||||
selectedIndex={this.state.selectedIndex}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentList>
|
||||
<IntentDetails selectedIntent={this.state.selectedIntent}
|
||||
onDeleteIntentClick={this.handleDeleteIntentClick}
|
||||
onSaveIntentClick={this.handleSaveIntentClick}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentDetails>
|
||||
</div>
|
||||
);
|
||||
render () {
|
||||
let rightPanel;
|
||||
switch (this.state.selectedIndex) {
|
||||
case LAUNCH_REQUEST_SELECTED_INDEX:
|
||||
rightPanel = (
|
||||
<LaunchRequest
|
||||
invocationName={this.state.invocationName}
|
||||
invocationAnswer={this.state.invocationAnswer}
|
||||
onSaveClick={this.handleSaveLaunchRequestClick}
|
||||
waiting={this.state.waiting}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
case CONTACT_SELECTED_INDEX:
|
||||
rightPanel = (
|
||||
<Contact
|
||||
contactEmail={this.state.contactEmail}
|
||||
onSaveEmailClick={this.handleSaveEmailClick}
|
||||
waiting={this.state.waiting}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
default:
|
||||
rightPanel = (
|
||||
<IntentDetails
|
||||
selectedIntent={this.state.selectedIntent}
|
||||
onDeleteIntentClick={this.handleDeleteIntentClick}
|
||||
onSaveIntentClick={this.handleSaveIntentClick}
|
||||
waiting={this.state.waiting}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<Popup />
|
||||
<div className="App-header">
|
||||
<h1> Tell All </h1>
|
||||
</div>
|
||||
<IntentList
|
||||
allIntents={this.state.allIntents}
|
||||
onLaunchRequestClick={this.handleLaunchRequestClick}
|
||||
onContactClick={this.handleContactClick}
|
||||
onIntentClick={this.handleIntentClick}
|
||||
onAddIntentClick={this.handleAddIntentClick}
|
||||
selectedIndex={this.state.selectedIndex}
|
||||
waiting={this.state.waiting}
|
||||
/>
|
||||
|
||||
{rightPanel}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
createSkill(intents, name, answer){
|
||||
createSkill (intents, name, answer, email, updateOnAmazon) {
|
||||
return {
|
||||
_id: this.state._id,
|
||||
skillID: this.state.skillID,
|
||||
intents: intents,
|
||||
invocationName: (name===undefined) ? this.state.invocationName : name,
|
||||
invocationAnswer: (answer===undefined)? this.state.invocationAnswer: answer
|
||||
invocationName: name,
|
||||
invocationAnswer: answer,
|
||||
contactEmail: email,
|
||||
updateOnAmazon: updateOnAmazon,
|
||||
};
|
||||
}
|
||||
|
||||
handleIntentClick(selectedIntent, index){
|
||||
this.setState({selectedIntent:selectedIntent, selectedIndex: index, launchRequest:false});
|
||||
handleIntentClick (selectedIntent, index) {
|
||||
this.setState ({
|
||||
selectedIntent: selectedIntent,
|
||||
selectedIndex: index,
|
||||
});
|
||||
}
|
||||
|
||||
handleLaunchRequestClick(){
|
||||
this.setState({selectedIndex: -2, launchRequest:true});
|
||||
handleLaunchRequestClick () {
|
||||
this.setState ({selectedIndex: LAUNCH_REQUEST_SELECTED_INDEX});
|
||||
}
|
||||
|
||||
handleSaveLaunchRequestClick(name, answer){
|
||||
this.setState({waiting:true, invocationName:name, invocationAnswer: answer});
|
||||
this.sendSkill(this.state.allIntents,true,{waiting:false},{waiting:false},name,answer);
|
||||
handleContactClick () {
|
||||
this.setState ({selectedIndex: CONTACT_SELECTED_INDEX});
|
||||
}
|
||||
|
||||
handleDeleteIntentClick(selectedIntent){
|
||||
handleSaveLaunchRequestClick (name, answer) {
|
||||
|
||||
if (name.length < INVOCATION_NAME_MIN_LENGTH){
|
||||
Popup.alert ('Invocation name should be at least 2 characters long');
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState ({
|
||||
waiting: true,
|
||||
invocationName: name,
|
||||
invocationAnswer: answer,
|
||||
});
|
||||
this.sendSkill (
|
||||
this.state.allIntents,
|
||||
true,
|
||||
{waiting: false},
|
||||
{waiting: false},
|
||||
name,
|
||||
answer,
|
||||
this.state.contactEmail,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
handleSaveEmailClick (email) {
|
||||
if (isEmailValid(email)){
|
||||
this.setState ({waiting: true});
|
||||
this.sendSkill (
|
||||
this.state.allIntents,
|
||||
true,
|
||||
{contactEmail: email, waiting: false},
|
||||
{waiting: false},
|
||||
this.state.invocationName,
|
||||
this.state.invocationAnswer,
|
||||
email,
|
||||
false
|
||||
);
|
||||
}else{
|
||||
Popup.alert ('Please enter valid email');
|
||||
}
|
||||
}
|
||||
|
||||
handleDeleteIntentClick (selectedIntent) {
|
||||
let id = -1;
|
||||
this.state.allIntents.map((intent,index)=>{
|
||||
if ((id===-1) && (JSON.stringify(selectedIntent)===JSON.stringify(intent)))
|
||||
id = index;
|
||||
//TODO : Change comparsion method ! Same object with different proeprty sorting will not be same string
|
||||
this.state.allIntents.map ((intent, index) => {
|
||||
if (
|
||||
id === -1 &&
|
||||
JSON.stringify (selectedIntent) === JSON.stringify (intent)
|
||||
)
|
||||
id = index;
|
||||
});
|
||||
|
||||
if (id!==-1){
|
||||
try{
|
||||
let newAllIntentsJSON = JSON.stringify(this.state.allIntents);
|
||||
let newAllIntents = JSON.parse(newAllIntentsJSON);
|
||||
newAllIntents.splice(id,1);
|
||||
this.setState({waiting:true});
|
||||
if (id !== -1) {
|
||||
try {
|
||||
let newAllIntentsJSON = JSON.stringify (this.state.allIntents);
|
||||
let newAllIntents = JSON.parse (newAllIntentsJSON);
|
||||
newAllIntents.splice (id, 1);
|
||||
this.setState ({waiting: true});
|
||||
|
||||
let newState = {allIntents: newAllIntents, selectedIntent: {intentName:'', questions:[''],answer:''}, waiting:false};
|
||||
this.sendSkill(newAllIntents,true,newState,{waiting:false});
|
||||
|
||||
}catch(e){
|
||||
console.log("error : " + e);
|
||||
let newState = {
|
||||
allIntents: newAllIntents,
|
||||
selectedIntent: {intentName: '', questions: [''], answer: ''},
|
||||
waiting: false,
|
||||
};
|
||||
this.sendSkill (
|
||||
newAllIntents,
|
||||
true,
|
||||
newState,
|
||||
{waiting: false},
|
||||
this.state.invocationName,
|
||||
this.state.invocationAnswer,
|
||||
this.state.contactEmail,
|
||||
true
|
||||
);
|
||||
} catch (e) {
|
||||
console.log ('error : ' + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
handleSaveIntentClick(selectedIntent){
|
||||
let newAllIntentsJSON = JSON.stringify(this.state.allIntents);
|
||||
let newAllIntents = JSON.parse(newAllIntentsJSON);
|
||||
handleSaveIntentClick (selectedIntent) {
|
||||
|
||||
let newState = null;
|
||||
if (this.state.selectedIndex === -1){
|
||||
//new intent
|
||||
newAllIntents.push(selectedIntent);
|
||||
newState = {allIntents: newAllIntents, selectedIntent: selectedIntent, selectedIndex: newAllIntents.length-1, waiting:false};
|
||||
}else{
|
||||
newAllIntents[this.state.selectedIndex] = selectedIntent;
|
||||
newState = {allIntents: newAllIntents, selectedIntent: selectedIntent, waiting: false};
|
||||
if (selectedIntent.intentName.length < INTENT_NAME_MIN_LENGTH){
|
||||
Popup.alert ('Question name should have at least 2 characters');
|
||||
return;
|
||||
}
|
||||
this.setState({waiting:true});
|
||||
this.sendSkill(newAllIntents, true, newState, {waiting:false});
|
||||
}
|
||||
|
||||
handleAddIntentClick(){
|
||||
this.setState({allIntents: this.state.allIntents, selectedIndex: -1,launchRequest:false,selectedIntent: {intentName:'',questions:[''], answer:''}});
|
||||
}
|
||||
if (selectedIntent.answer.length < ANSWER_MIN_LENGTH){
|
||||
Popup.alert('Answer should have at least 2 characters');
|
||||
return;
|
||||
}
|
||||
|
||||
sendSkill(newAllIntents, showPopUp, resolveState, rejectState, newName, newAnswer){
|
||||
return new Promise((resolve,reject)=>{
|
||||
updateSkill(this.createSkill(newAllIntents,newName,newAnswer)).then(l=>l.text()).then(result=>{
|
||||
let jResult = JSON.parse(result);
|
||||
if (jResult.result !== 0){
|
||||
if (showPopUp) Popup.alert('Model was not saved. Please try again');
|
||||
this.setState(rejectState);
|
||||
//reject('Error code : ' + jResult.result);
|
||||
}else{
|
||||
if (showPopUp) Popup.alert('Saved');
|
||||
this.setState(resolveState);
|
||||
resolve();
|
||||
for(let i=0;i<selectedIntent.questions.length;i++){
|
||||
if (selectedIntent.questions[i].length < QUESTION_MIN_LENGTH){
|
||||
Popup.alert('Question variant should have at least 2 characters');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Check for same question variants and same question name in other intents
|
||||
|
||||
for (let i=0;i<this.state.allIntents.length;i++){
|
||||
if (i!==this.state.selectedIndex){
|
||||
if (selectedIntent.intentName === this.state.allIntents[i].intentName){
|
||||
Popup.alert('Question name already exists');
|
||||
return;
|
||||
}
|
||||
}).catch(e=>{
|
||||
if (showPopUp) Popup.alert('Model was not saved. Please try again');
|
||||
this.setState(rejectState);
|
||||
//reject(e);
|
||||
});
|
||||
|
||||
for(let j=0;j<selectedIntent.questions.length;j++){
|
||||
for (let k=0;k<this.state.allIntents[i].questions.length;k++){
|
||||
if (selectedIntent.questions[j] === this.state.allIntents[i].questions[k]){
|
||||
Popup.alert('Question variant already exists (in question :' + this.state.allIntents[i].intentName + ')');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let newAllIntentsJSON = JSON.stringify (this.state.allIntents);
|
||||
let newAllIntents = JSON.parse (newAllIntentsJSON);
|
||||
|
||||
let resolveState = null;
|
||||
let rejectState = {waiting:false}
|
||||
|
||||
if (this.state.selectedIndex === NEW_INTENT_SELECTED_INDEX) {
|
||||
//new intent
|
||||
newAllIntents.push (selectedIntent);
|
||||
resolveState = {
|
||||
allIntents: newAllIntents,
|
||||
selectedIntent: selectedIntent,
|
||||
selectedIndex: newAllIntents.length - 1,
|
||||
waiting: false,
|
||||
};
|
||||
} else {
|
||||
newAllIntents[this.state.selectedIndex] = selectedIntent;
|
||||
resolveState = {
|
||||
allIntents: newAllIntents,
|
||||
selectedIntent: selectedIntent,
|
||||
waiting:false,
|
||||
};
|
||||
}
|
||||
this.setState ({waiting: true});
|
||||
this.sendSkill (
|
||||
newAllIntents,
|
||||
true,
|
||||
resolveState,
|
||||
rejectState,
|
||||
this.state.invocationName,
|
||||
this.state.invocationAnswer,
|
||||
this.state.contactEmail,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
handleAddIntentClick () {
|
||||
this.setState ({
|
||||
allIntents: this.state.allIntents,
|
||||
selectedIndex: NEW_INTENT_SELECTED_INDEX,
|
||||
launchRequest: false,
|
||||
selectedIntent: {intentName: '', questions: [''], answer: '', intentExplanation:''},
|
||||
});
|
||||
}
|
||||
|
||||
sendSkill (
|
||||
newAllIntents,
|
||||
showPopUp,
|
||||
resolveState,
|
||||
rejectState,
|
||||
newName,
|
||||
newAnswer,
|
||||
email,
|
||||
updateOnAmazon
|
||||
) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
updateSkill (
|
||||
this.createSkill (
|
||||
newAllIntents,
|
||||
newName,
|
||||
newAnswer,
|
||||
email,
|
||||
updateOnAmazon
|
||||
)
|
||||
)
|
||||
.then (l => l.json ())
|
||||
.then (result => {
|
||||
if (result.result !== RESULT_CODES.OK) {
|
||||
console.log (result);
|
||||
if (showPopUp)
|
||||
Popup.alert ('Model was not saved. Please try again');
|
||||
this.setState (rejectState);
|
||||
//reject('Error code : ' + jResult.result);
|
||||
} else {
|
||||
if (showPopUp) Popup.alert ('Saved');
|
||||
this.setState (resolveState);
|
||||
resolve ();
|
||||
}
|
||||
})
|
||||
.catch (e => {
|
||||
console.log ('error : ' + e);
|
||||
if (showPopUp) Popup.alert ('Model was not saved. Please try again');
|
||||
this.setState (rejectState);
|
||||
//reject(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
48
web/src/components/Contact.js
Normal file
48
web/src/components/Contact.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Button, TextField} from 'react-md';
|
||||
import '../css/Common.css';
|
||||
import '../css/components/Contact.css';
|
||||
import {EMAIL_MAX_LENGTH} from '../config/constants';
|
||||
|
||||
class Contact extends Component {
|
||||
constructor(props){
|
||||
super(props);
|
||||
|
||||
this.state = {contactEmail: props.contactEmail};
|
||||
|
||||
this.handleEmailEdit = this.handleEmailEdit.bind(this);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(props){
|
||||
this.setState({contactEmail: props.contactEmail});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="RightPanelBox">
|
||||
<h5 className="PanelSubTitle"> Contact address will be used for direct messaging through Alexa </h5>
|
||||
<TextField
|
||||
id="contact email"
|
||||
lineDirection="center"
|
||||
label="Contact email"
|
||||
className="md-cell md-cell--bottom ContactEmailInput"
|
||||
maxLength={EMAIL_MAX_LENGTH}
|
||||
onChange={this.handleEmailEdit}
|
||||
value={this.state.contactEmail}/>
|
||||
<br></br>
|
||||
<br></br>
|
||||
<br></br>
|
||||
<Button className="SaveButton" flat primary swapTheming
|
||||
onClick={()=>{this.props.onSaveEmailClick(this.state.contactEmail)}}
|
||||
disabled={this.props.waiting}>Save</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
handleEmailEdit(e){
|
||||
if (e.length === EMAIL_MAX_LENGTH) return;
|
||||
this.setState({contactEmail: e});
|
||||
}
|
||||
}
|
||||
|
||||
export default Contact;
|
||||
@@ -1,7 +1,8 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Button, SVGIcon, TextField} from 'react-md';
|
||||
import '../css/Intent.css'
|
||||
import {QUESTION_MAX_LENGTH, ANSWER_MAX_LENGTH, INTENT_NAME_MAX_LENGTH} from '../config';
|
||||
import '../css/components/IntentDetails.css';
|
||||
import '../css/Common.css';
|
||||
import {QUESTION_MAX_LENGTH, ANSWER_MAX_LENGTH, INTENT_NAME_MAX_LENGTH, INTENT_EXPLANATION_MAX_LENGTH} from '../config/constants';
|
||||
|
||||
class IntentDetails extends Component {
|
||||
constructor(props){
|
||||
@@ -14,6 +15,7 @@ class IntentDetails extends Component {
|
||||
this.handleQuestionEdit = this.handleQuestionEdit.bind(this);
|
||||
this.handleAnswerEdit = this.handleAnswerEdit.bind(this);
|
||||
this.handleIntentNameEdit = this.handleIntentNameEdit.bind(this);
|
||||
this.handleIntentExplanationEdit = this.handleIntentExplanationEdit.bind(this);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(props){
|
||||
@@ -22,20 +24,28 @@ class IntentDetails extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="IntentDetails">
|
||||
<div className="RightPanelBox">
|
||||
<div className="QuestionBox">
|
||||
<h5 className="PanelSubTitle"> In introduction, Alexa will help users to ask her the right questions about your business. For Example, she will say : "To ask us about our services, say : What do you do ? ". What do you do ? is defined in question field. Alexa will use first variation of question in intro.</h5>
|
||||
<TextField
|
||||
id="intent explanation"
|
||||
lineDirection="center"
|
||||
placeholder="To ask us about our services, say "
|
||||
className="md-cell md-cell--bottom IntentDetailsInputBoxes"
|
||||
onChange={this.handleIntentExplanationEdit}
|
||||
maxLength={INTENT_EXPLANATION_MAX_LENGTH}
|
||||
value={this.state.intent.intentExplanation} />
|
||||
<br/>
|
||||
<TextField
|
||||
id="intent name"
|
||||
lineDirection="center"
|
||||
placeholder="Intent name"
|
||||
label="Intent name"
|
||||
className="md-cell md-cell--bottom"
|
||||
style={{width:'60%'}}
|
||||
label="Question name"
|
||||
className="md-cell md-cell--bottom IntentDetailsInputBoxes"
|
||||
onChange={this.handleIntentNameEdit}
|
||||
maxLength={INTENT_NAME_MAX_LENGTH}
|
||||
value={this.state.intent.intentName} />
|
||||
</div>
|
||||
<h5 style={{marginTop:'20px', marginLeft: '30px', float: 'left'}}>Questions</h5>
|
||||
<h5 className="QuestionTitle">Question variants</h5>
|
||||
{
|
||||
this.state.intent.questions.map((question, index)=>{
|
||||
return (
|
||||
@@ -44,8 +54,7 @@ class IntentDetails extends Component {
|
||||
id="intent question"
|
||||
lineDirection="center"
|
||||
placeholder="Question"
|
||||
className="md-cell md-cell--bottom"
|
||||
style={{width:'60%'}}
|
||||
className="md-cell md-cell--bottom IntentDetailsInputBoxes"
|
||||
maxLength={QUESTION_MAX_LENGTH}
|
||||
rightIcon={<SVGIcon onClick={()=>{this.deleteQuestion(question)}}> <path fill="#000000" d="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z"/> </SVGIcon>}
|
||||
onChange={(e)=>{this.handleQuestionEdit(e,index)}}
|
||||
@@ -62,18 +71,17 @@ class IntentDetails extends Component {
|
||||
lineDirection="center"
|
||||
label="Answer"
|
||||
placeholder="Answer"
|
||||
style={{width:'60%'}}
|
||||
maxLength={ANSWER_MAX_LENGTH}
|
||||
className="md-cell md-cell--bottom"
|
||||
className="md-cell md-cell--bottom IntentDetailsInputBoxes"
|
||||
onChange={this.handleAnswerEdit}
|
||||
value={this.state.intent.answer}/>
|
||||
</div>
|
||||
}
|
||||
<br></br>
|
||||
<br></br>
|
||||
<Button style={{float:'left', marginLeft: '25px'}} flat primary onClick={()=>{this.props.onDeleteIntentClick(this.state.intent)}} disabled={this.props.waiting}>Delete intent</Button>
|
||||
<Button style={{float:'left', marginLeft: '22%'}} flat primary swapTheming onClick={this.addQuestion} disabled={this.props.waiting}>Add question</Button>
|
||||
<Button style={{float:'left', marginLeft: '20px'}} flat primary swapTheming onClick={()=>{this.props.onSaveIntentClick(this.state.intent)}} disabled={this.props.waiting}>Save</Button>
|
||||
<Button className="IntentDetailsButton" flat primary onClick={()=>{this.props.onDeleteIntentClick(this.state.intent)}} disabled={this.props.waiting}>Delete question</Button>
|
||||
<Button className="IntentDetailsButton" flat primary swapTheming onClick={this.addQuestion} disabled={this.props.waiting}>Add variant</Button>
|
||||
<Button className="IntentDetailsButton" flat primary swapTheming onClick={()=>{this.props.onSaveIntentClick(this.state.intent)}} disabled={this.props.waiting}>Save</Button>
|
||||
|
||||
</div>
|
||||
);
|
||||
@@ -95,22 +103,28 @@ class IntentDetails extends Component {
|
||||
}
|
||||
|
||||
handleQuestionEdit(e,index){
|
||||
if (e.length === QUESTION_MAX_LENGTH) return;
|
||||
if (e.length === QUESTION_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.questions[index] = e;
|
||||
this.setState({intent: newIntent});
|
||||
}
|
||||
|
||||
handleIntentExplanationEdit(e,index){
|
||||
if (e.length === INTENT_EXPLANATION_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.intentExplanation = e;
|
||||
this.setState({intent: newIntent});
|
||||
}
|
||||
|
||||
handleAnswerEdit(e){
|
||||
if (e.length === ANSWER_MAX_LENGTH) return;
|
||||
if (e.length === ANSWER_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.answer = e;
|
||||
this.setState({intent: newIntent});
|
||||
}
|
||||
|
||||
handleIntentNameEdit(e){
|
||||
if (e.length === INTENT_NAME_MAX_LENGTH) return;
|
||||
//e.replace(/\s/g,'');
|
||||
if (e.length === INTENT_NAME_MAX_LENGTH || !(/^[a-z]*$/i.test(e))) return;
|
||||
let newIntent = this.state.intent;
|
||||
newIntent.intentName = e;
|
||||
this.setState({intent: newIntent});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Button} from 'react-md';
|
||||
import '../css/Intent.css'
|
||||
import {INTENT_TITLE_MAX_LENGTH, INTENT_TITLE_TOOLTIP_DELAY} from '../config'
|
||||
import '../css/components/IntentItem.css'
|
||||
import {INTENT_TITLE_MAX_LENGTH, INTENT_TITLE_TOOLTIP_DELAY} from '../config/constants'
|
||||
|
||||
class IntentItem extends Component {
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Button} from 'react-md';
|
||||
import IntentItem from './IntentItem';
|
||||
import '../css/Intent.css'
|
||||
import '../css/components/IntentList.css';
|
||||
import {
|
||||
LAUNCH_REQUEST_SELECTED_INDEX,
|
||||
CONTACT_SELECTED_INDEX} from '../config/constants'
|
||||
|
||||
class IntentList extends Component {
|
||||
constructor (props){
|
||||
@@ -17,11 +20,17 @@ class IntentList extends Component {
|
||||
render() {
|
||||
return (
|
||||
<div className="IntentList">
|
||||
<Button className={this.props.selectedIndex===-2 ? "LaunchRequest-selected" : "LaunchRequest"} flat primary
|
||||
<Button className={this.props.selectedIndex===LAUNCH_REQUEST_SELECTED_INDEX ? "LaunchRequestButton-selected" : "LaunchRequestButton"} flat primary
|
||||
onClick={this.props.onLaunchRequestClick}
|
||||
disabled={this.props.waiting} >Launch request</Button>
|
||||
|
||||
<Button className={this.props.selectedIndex===CONTACT_SELECTED_INDEX ? "ContactButton-selected" : "ContactButton"} flat primary
|
||||
onClick={this.props.onContactClick}
|
||||
disabled={this.props.waiting} >Contact</Button>
|
||||
|
||||
|
||||
<div className="IntentList-title">
|
||||
<h3>Intents</h3>
|
||||
<h3>Questions</h3>
|
||||
</div>
|
||||
{
|
||||
this.state.intents.map((intent,index)=>{
|
||||
@@ -34,9 +43,9 @@ class IntentList extends Component {
|
||||
})
|
||||
}
|
||||
<br></br>
|
||||
<Button className={"AddIntent"} flat primary swapTheming
|
||||
<Button className="AddIntent" flat primary swapTheming
|
||||
onClick={this.props.onAddIntentClick}
|
||||
disabled={this.props.waiting}>Add intent</Button>
|
||||
disabled={this.props.waiting}>Add question</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Button, TextField} from 'react-md';
|
||||
import '../css/Intent.css'
|
||||
import { INVOCATION_NAME_MAX_LENGTH, INVOCATION_ANSWER_MAX_LENGTH } from '../config';
|
||||
import '../css/Common.css';
|
||||
import '../css/components/LaunchRequest.css';
|
||||
import { INVOCATION_NAME_MAX_LENGTH, INVOCATION_ANSWER_MAX_LENGTH } from '../config/constants';
|
||||
|
||||
class LaunchRequest extends Component {
|
||||
constructor(props){
|
||||
@@ -19,33 +20,31 @@ class LaunchRequest extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="LaunchRequestBox">
|
||||
<h5 style={{textAlign:'left', marginTop: '30px', marginLeft: '20px'}}> Invocation name customers use to activate the skill. For example "Open Saburly" or "Talk to Saburly" </h5>
|
||||
<div className="RightPanelBox">
|
||||
<h5 className="PanelSubTitle"> Invocation name customers use to activate the skill. For example "Open Saburly" or "Talk to Saburly" </h5>
|
||||
<TextField
|
||||
id="invocation name"
|
||||
lineDirection="center"
|
||||
placeholder="Saburly"
|
||||
label="Invocation name"
|
||||
className="md-cell md-cell--bottom"
|
||||
style={{width:'60%', marginLeft: '20px'}}
|
||||
className="md-cell md-cell--bottom InvocationInputBoxes"
|
||||
maxLength={INVOCATION_NAME_MAX_LENGTH}
|
||||
onChange={this.handleNameEdit}
|
||||
value={this.state.invocationName}/>
|
||||
<br></br>
|
||||
<h5 style={{textAlign:'left', marginLeft: '20px', marginTop: '30px'}}>Answer customers get from Alexa when they activate the skill.</h5>
|
||||
<h5 className="PanelSubTitle" >Answer customers get from Alexa when they activate the skill.</h5>
|
||||
<TextField
|
||||
id="invocation answer"
|
||||
lineDirection="center"
|
||||
placeholder="We are Saburly, ask us something about us"
|
||||
label="Answer"
|
||||
className="md-cell md-cell--bottom"
|
||||
style={{width:'60%', marginLeft: '20px'}}
|
||||
className="md-cell md-cell--bottom InvocationInputBoxes"
|
||||
maxLength={INVOCATION_ANSWER_MAX_LENGTH}
|
||||
onChange={this.handleAnswerEdit}
|
||||
value={this.state.invocationAnswer}/>
|
||||
<br></br>
|
||||
<br></br>
|
||||
<Button style={{float:'right', marginRight: '20px'}} flat primary swapTheming
|
||||
<Button className="SaveButton" flat primary swapTheming
|
||||
onClick={()=>{this.props.onSaveClick(this.state.invocationName, this.state.invocationAnswer)}}
|
||||
disabled={this.props.waiting}>Save</Button>
|
||||
</div>
|
||||
@@ -53,12 +52,12 @@ class LaunchRequest extends Component {
|
||||
}
|
||||
|
||||
handleNameEdit(e){
|
||||
if (e.length === INVOCATION_NAME_MAX_LENGTH) return;
|
||||
if (e.length === INVOCATION_NAME_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
this.setState({invocationName: e});
|
||||
}
|
||||
|
||||
handleAnswerEdit(e){
|
||||
if (e.length === INVOCATION_ANSWER_MAX_LENGTH) return;
|
||||
if (e.length === INVOCATION_ANSWER_MAX_LENGTH || !(/^[a-z,.' ]*$/i.test(e))) return;
|
||||
this.setState({invocationAnswer: e});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
export const BASE_URL = 'localhost:5000';
|
||||
|
||||
export const INTENT_NAME_MAX_LENGTH = 30;
|
||||
export const QUESTION_MAX_LENGTH = 150;
|
||||
export const ANSWER_MAX_LENGTH = 150;
|
||||
|
||||
export const INTENT_TITLE_MAX_LENGTH = 20;
|
||||
export const INTENT_TITLE_TOOLTIP_DELAY = 700;
|
||||
|
||||
export const INVOCATION_NAME_MAX_LENGTH = 15;
|
||||
export const INVOCATION_ANSWER_MAX_LENGTH = 100;
|
||||
4
web/src/config/config.js
Normal file
4
web/src/config/config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
//export const BASE_URL = 'tellall.saburly.com'; //for server
|
||||
export const BASE_URL = 'localhost:5000'; //for local
|
||||
|
||||
|
||||
28
web/src/config/constants.js
Normal file
28
web/src/config/constants.js
Normal file
@@ -0,0 +1,28 @@
|
||||
export const INTENT_EXPLANATION_MAX_LENGTH = 70;
|
||||
|
||||
export const INTENT_NAME_MAX_LENGTH = 30;
|
||||
export const INTENT_NAME_MIN_LENGTH = 2;
|
||||
|
||||
export const QUESTION_MAX_LENGTH = 150;
|
||||
export const QUESTION_MIN_LENGTH = 2;
|
||||
|
||||
export const ANSWER_MAX_LENGTH = 150;
|
||||
export const ANSWER_MIN_LENGTH = 2;
|
||||
|
||||
export const INTENT_TITLE_MAX_LENGTH = 20;
|
||||
export const INTENT_TITLE_TOOLTIP_DELAY = 700;
|
||||
|
||||
export const INVOCATION_NAME_MAX_LENGTH = 50;
|
||||
export const INVOCATION_NAME_MIN_LENGTH = 2;
|
||||
export const INVOCATION_ANSWER_MAX_LENGTH = 100;
|
||||
|
||||
export const EMAIL_MAX_LENGTH = 100;
|
||||
|
||||
export const NEW_INTENT_SELECTED_INDEX = -1;
|
||||
export const LAUNCH_REQUEST_SELECTED_INDEX = -2;
|
||||
export const CONTACT_SELECTED_INDEX = -3;
|
||||
|
||||
export const RESULT_CODES = {
|
||||
OK: 0,
|
||||
ERROR: -1,
|
||||
};
|
||||
21
web/src/css/Common.scss
Normal file
21
web/src/css/Common.scss
Normal file
@@ -0,0 +1,21 @@
|
||||
$minHeight : calc(100vh - 80px); //80px is height of the title div container
|
||||
|
||||
/* Common for right panel components */
|
||||
|
||||
.RightPanelBox{
|
||||
float: left;
|
||||
width: 70%;
|
||||
min-height:$minHeight;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.PanelSubTitle{
|
||||
text-align: left;
|
||||
margin-top: 30px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.SaveButton{
|
||||
float: right;
|
||||
margin-right: 20px;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*IntentList and IntentItem CSS*/
|
||||
.IntentList {
|
||||
width: 30%;
|
||||
min-height: calc(100vh - 80px);
|
||||
float: left;
|
||||
background-color: #eff0f0; }
|
||||
|
||||
.IntentList-title {
|
||||
font-size: 1.5em;
|
||||
height: 70px;
|
||||
padding: 20px;
|
||||
text-align: left;
|
||||
background-color: #eff0f0; }
|
||||
|
||||
.LaunchRequest {
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #d8d8d8; }
|
||||
|
||||
.LaunchRequest-selected {
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #f5f5f5; }
|
||||
|
||||
.AddIntent {
|
||||
float: right;
|
||||
margin: 12px; }
|
||||
|
||||
.IntentItem {
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background-color: #d8d8d8; }
|
||||
|
||||
.IntentItem-selected {
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
background-color: #f5f5f5; }
|
||||
|
||||
/*IntentDetails CSS*/
|
||||
.IntentDetails {
|
||||
float: left;
|
||||
width: 70%;
|
||||
min-height: calc(100vh - 80px);
|
||||
background-color: #f5f5f5; }
|
||||
|
||||
.QuestionBox {
|
||||
margin: 25px; }
|
||||
|
||||
/*LaunchRequest CSS*/
|
||||
.LaunchRequestBox {
|
||||
float: left;
|
||||
width: 70%;
|
||||
min-height: calc(100vh - 80px);
|
||||
background-color: #f5f5f5; }
|
||||
|
||||
.ExplanationText {
|
||||
float: left;
|
||||
margin-top: 30px;
|
||||
margin-left: 20px;
|
||||
text-align: left; }
|
||||
@@ -1,85 +0,0 @@
|
||||
$minHeight : calc(100vh - 80px);
|
||||
|
||||
/*IntentList and IntentItem CSS*/
|
||||
|
||||
.IntentList{
|
||||
width: 30%;
|
||||
min-height:$minHeight;
|
||||
float:left;
|
||||
background-color: #eff0f0;
|
||||
}
|
||||
|
||||
.IntentList-title{
|
||||
font-size: 1.5em;
|
||||
height: 70px;
|
||||
padding: 20px;
|
||||
text-align:left;
|
||||
background-color: #eff0f0;
|
||||
}
|
||||
|
||||
.LaunchRequest{
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #d8d8d8
|
||||
}
|
||||
|
||||
.LaunchRequest-selected{
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.AddIntent{
|
||||
float: right;
|
||||
margin: 12px;
|
||||
}
|
||||
|
||||
.IntentItem{
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
height: 50px;
|
||||
width:100%;
|
||||
text-align:left;
|
||||
background-color: #d8d8d8;
|
||||
}
|
||||
|
||||
.IntentItem-selected{
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
height: 50px;
|
||||
width:100%;
|
||||
text-align:left;
|
||||
background-color: #f5f5f5;
|
||||
|
||||
}
|
||||
|
||||
/*IntentDetails CSS*/
|
||||
|
||||
.IntentDetails{
|
||||
float: left;
|
||||
width: 70%;
|
||||
min-height:$minHeight;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.QuestionBox{
|
||||
margin:25px;
|
||||
}
|
||||
|
||||
/*LaunchRequest CSS*/
|
||||
|
||||
.LaunchRequestBox{
|
||||
float: left;
|
||||
width:70%;
|
||||
min-height:$minHeight;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.ExplanationText{
|
||||
float: left;
|
||||
margin-top: 30px;
|
||||
margin-left: 20px;
|
||||
text-align: left;
|
||||
}
|
||||
4
web/src/css/components/Contact.scss
Normal file
4
web/src/css/components/Contact.scss
Normal file
@@ -0,0 +1,4 @@
|
||||
.ContactEmailInput{
|
||||
width: 60%;
|
||||
margin-left: 20px;
|
||||
}
|
||||
18
web/src/css/components/IntentDetails.scss
Normal file
18
web/src/css/components/IntentDetails.scss
Normal file
@@ -0,0 +1,18 @@
|
||||
.QuestionBox{
|
||||
margin:25px;
|
||||
}
|
||||
|
||||
.QuestionTitle{
|
||||
margin-top:20px;
|
||||
margin-left: 30px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.IntentDetailsInputBoxes{
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
.IntentDetailsButton{
|
||||
float: left;
|
||||
margin-left: 25px;
|
||||
}
|
||||
18
web/src/css/components/IntentItem.scss
Normal file
18
web/src/css/components/IntentItem.scss
Normal file
@@ -0,0 +1,18 @@
|
||||
.IntentItem{
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
height: 50px;
|
||||
width:100%;
|
||||
text-align:left;
|
||||
background-color: #d8d8d8;
|
||||
}
|
||||
|
||||
.IntentItem-selected{
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
height: 50px;
|
||||
width:100%;
|
||||
text-align:left;
|
||||
background-color: #f5f5f5;
|
||||
|
||||
}
|
||||
52
web/src/css/components/IntentList.scss
Normal file
52
web/src/css/components/IntentList.scss
Normal file
@@ -0,0 +1,52 @@
|
||||
$minHeight : calc(100vh - 80px); //80px is height of the title div container
|
||||
|
||||
|
||||
.IntentList{
|
||||
width: 30%;
|
||||
min-height:$minHeight;
|
||||
float:left;
|
||||
background-color: #eff0f0;
|
||||
}
|
||||
|
||||
.IntentList-title{
|
||||
font-size: 1.5em;
|
||||
height: 70px;
|
||||
padding: 20px;
|
||||
text-align:left;
|
||||
background-color: #eff0f0;
|
||||
}
|
||||
|
||||
.AddIntent{
|
||||
float: right;
|
||||
margin: 12px;
|
||||
}
|
||||
|
||||
.LaunchRequestButton{
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #d8d8d8
|
||||
}
|
||||
|
||||
.LaunchRequestButton-selected{
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.ContactButton{
|
||||
text-align: left;
|
||||
color: #009b8a;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #d8d8d8
|
||||
}
|
||||
|
||||
.ContactButton-selected{
|
||||
text-align: left;
|
||||
color: #009b8a;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
11
web/src/css/components/LaunchRequest.scss
Normal file
11
web/src/css/components/LaunchRequest.scss
Normal file
@@ -0,0 +1,11 @@
|
||||
.ExplanationText{
|
||||
float: left;
|
||||
margin-top: 30px;
|
||||
margin-left: 20px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.InvocationInputBoxes{
|
||||
width: 60%;
|
||||
margin-left: 20px;
|
||||
}
|
||||
@@ -1,26 +1,16 @@
|
||||
import fetch from 'isomorphic-fetch';
|
||||
import {BASE_URL} from '../config';
|
||||
|
||||
export const getAllIntents = (id)=>{
|
||||
let url = `http://${BASE_URL}/intents/${id}`
|
||||
return fetch(url, {method: 'GET'});
|
||||
}
|
||||
import {BASE_URL} from '../config/config';
|
||||
|
||||
export const getSkill = (id)=>{
|
||||
let url = `http://${BASE_URL}/getSkill/${id}`
|
||||
return fetch(url, {method: 'GET'});
|
||||
}
|
||||
|
||||
export const deleteSkill = (id)=>{
|
||||
let url = `http://${BASE_URL}/deleteSkill/${id}`
|
||||
let url = `http://${BASE_URL}/skill/${id}`
|
||||
return fetch(url, {method: 'GET'});
|
||||
}
|
||||
|
||||
export const updateSkill = (skill)=>{
|
||||
let id = (skill._id) ? skill._id : -1;
|
||||
let url = `http://${BASE_URL}/updateSkill/${id}`
|
||||
let url = `http://${BASE_URL}/skill/${id}`
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
5
web/src/lib/helpers.js
Normal file
5
web/src/lib/helpers.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export const isEmailValid = email => {
|
||||
let validEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
|
||||
return validEmailRegex.test (email);
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
|
||||
<g fill="#61DAFB">
|
||||
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
|
||||
<circle cx="420.9" cy="296.5" r="45.7"/>
|
||||
<path d="M520.5 78.1z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.6 KiB |
Reference in New Issue
Block a user