Skip to content

Commit

Permalink
Handle attachments. Enable/disable public folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
hinojosachapel committed May 23, 2021
1 parent 8e9aea1 commit 28e0cf3
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 26 deletions.
10 changes: 8 additions & 2 deletions javascript_nodejs/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
"version": "0.2.0",
"configurations": [
{
"type": "node",
"type": "pwa-node",
"request": "launch",
"name": "dev",
"program": "${workspaceFolder}/src/index.js"
"program": "${workspaceFolder}/src/index.js",
"trace": true,
"sourceMaps": true,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
]
}
]
}
3 changes: 2 additions & 1 deletion javascript_nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"databaseId": "<YOUR_DATABASE_ID>",
"containerId": "<YOUR_COLLECTION_ID>"
},
"publicResourcesUrl": "http://localhost:3978"
"publicResourcesUrl": "http://localhost:3978",
"allowPublicFolder": "true"
}
```

Expand Down
4 changes: 2 additions & 2 deletions javascript_nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"license": "MIT",
"main": "index.js",
"scripts": {
"start": "node ./index.js",
"watch": "nodemon ./index.js",
"start": "node ./src/index.js",
"watch": "nodemon ./src/index.js",
"lint": "./node_modules/.bin/eslint .",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
7 changes: 7 additions & 0 deletions javascript_nodejs/src/dialogs/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ class MainDialog extends ComponentDialog {
let turnResult = DIALOG_TURN_RESULT_DEFAULT;
const utterance = (dc.context.activity.text || '').trim().toLowerCase();

// Look for attachments. Only answer if no text message.
if (utterance.length === 0 && dc.context.activity.attachments && dc.context.activity.attachments.length > 0) {
// The user sent an attachment and the bot should handle the incoming attachment.
await dc.context.sendActivity(localizer.gettext(locale, 'attachmentResponse'));
return DIALOG_TURN_RESULT_DEFAULT;
}

// Handle commands
if (utterance === localizer.gettext(locale, 'restartCommand').toLowerCase()) {
let userData = new UserData();
Expand Down
4 changes: 2 additions & 2 deletions javascript_nodejs/src/dialogs/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Utils {
}

return {
value: 'yes',
value: title,
action: {
type: 'imBack',
title: title,
Expand All @@ -104,7 +104,7 @@ class Utils {
}

return {
value: 'no',
value: title,
action: {
type: 'imBack',
title: title,
Expand Down
10 changes: 6 additions & 4 deletions javascript_nodejs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ server.listen(process.env.port || process.env.PORT || 3978, () => {
console.log('\nGet more info at: https://github.com/microsoft/BotFramework-Emulator/wiki/Getting-Started');
});

// Serve static files
server.get('/public/*', restify.plugins.serveStatic({
directory: __dirname
}));
if (appsettings.allowPublicFolder === 'true') {
// Serve static files
server.get('/public/*', restify.plugins.serveStatic({
directory: __dirname
}));
}

// Listen for incoming activities and route them to your bot main dialog.
server.post('/api/messages', (req, res) => {
Expand Down
1 change: 1 addition & 0 deletions javascript_nodejs/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
]
},
"readyPrompt": "What can I do for you? \r (Choose one or type your own question)",
"attachmentResponse": "Thanks! 👍",
"profanity": "That hurt my feelings. 😓 If you are stuck, just type \"**help**\" and I'll tell you some hints.",
"restartCommand": "Restart"
}
2 changes: 1 addition & 1 deletion javascript_nodejs/src/public/webchat.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Coreplus Chatbot</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8" />
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html, body { height: 100% }
body { margin: 0 }
Expand Down
21 changes: 15 additions & 6 deletions typescript_nodejs/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"version": "0.2.0",
"configurations": [
{
"type": "node",
"type": "pwa-node",
"request": "launch",
"name": "dev Typescript",
"name": "dev Typescript",
"args": [
"src/index.ts"
],
Expand All @@ -16,14 +16,23 @@
"ts-node/register"
],
"cwd": "${workspaceFolder}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
"internalConsoleOptions": "openOnSessionStart",
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
]
},
{
"type": "node",
"type": "pwa-node",
"request": "launch",
"name": "dev JavaScript",
"program": "${workspaceFolder}/build/index.js"
"program": "${workspaceFolder}/build/index.js",
"trace": true,
"sourceMaps": true,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
]
}
]
}
3 changes: 2 additions & 1 deletion typescript_nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"databaseId": "<YOUR_DATABASE_ID>",
"containerId": "<YOUR_COLLECTION_ID>"
},
"publicResourcesUrl": "http://localhost:3978"
"publicResourcesUrl": "http://localhost:3978",
"allowPublicFolder": "true"
}
```

Expand Down
7 changes: 7 additions & 0 deletions typescript_nodejs/src/dialogs/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ export class MainDialog extends ComponentDialog {
let turnResult: DialogTurnResult = DIALOG_TURN_RESULT_DEFAULT;
const utterance: string = (dc.context.activity.text || '').trim().toLowerCase();

// Look for attachments. Only answer if no text message.
if (utterance.length === 0 && dc.context.activity.attachments && dc.context.activity.attachments.length > 0) {
// The user sent an attachment and the bot should handle the incoming attachment.
await dc.context.sendActivity(localizer.gettext(locale, 'attachmentResponse'));
return DIALOG_TURN_RESULT_DEFAULT;
}

// Handle commands
if (utterance === localizer.gettext(locale, 'restartCommand').toLowerCase()) {
const userData: UserData = new UserData();
Expand Down
4 changes: 2 additions & 2 deletions typescript_nodejs/src/dialogs/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Utils {
}

return {
value: 'yes',
value: title,
action: {
type: 'imBack',
title: title,
Expand All @@ -107,7 +107,7 @@ export class Utils {
}

return {
value: 'no',
value: title,
action: {
type: 'imBack',
title: title,
Expand Down
10 changes: 6 additions & 4 deletions typescript_nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ server.listen(process.env.port || process.env.PORT || 3978, (): void => {
console.log('\nGet more info at: https://github.com/microsoft/BotFramework-Emulator/wiki/Getting-Started');
});

// Serve static files
server.get('/public/*', restify.plugins.serveStatic({
directory: __dirname
}));
if (appsettings.allowPublicFolder === 'true') {
// Serve static files
server.get('/public/*', restify.plugins.serveStatic({
directory: __dirname
}));
}

// Listen for incoming activities and route them to your bot main dialog.
server.post('/api/messages', (req: restify.Request, res: restify.Response) => {
Expand Down
1 change: 1 addition & 0 deletions typescript_nodejs/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"cancel": ["cancel", "abort"]
},
"readyPrompt": "What can I do for you? \r (Choose one or type your own question)",
"attachmentResponse": "Thanks! 👍",
"profanity": "That hurt my feelings. 😓 If you are stuck, just type \"**help**\" and I'll tell you some hints.",
"restartCommand": "Restart"
}
2 changes: 1 addition & 1 deletion typescript_nodejs/src/public/webchat.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Coreplus Chatbot</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8" />
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html, body { height: 100% }
body { margin: 0 }
Expand Down

0 comments on commit 28e0cf3

Please sign in to comment.