
# Node.jsのプロジェクトを管理したいディレクトリから
$ sap-cloud-sdk init node-sdk-chat
This folder does not contain a `package.json`.
Should a new `nest.js` project be initialized in this folder? (y|n): y
Building application scaffold... done
Enter project name (for use in manifest.yml) [node-sdk-chat]: node-sdk-chat
Do you want to provide anonymous usage analytics to help us improve the SDK? (y|n): n
✔ Creating files
✔ Modifying test config
✔ Adding dependencies to package.json
✔ Installing dependencies
✔ Modifying `.gitignore`
+--------------------------------------------------------------+
✅ Init finished successfully.
? Next steps:
- Run the application locally (`npm run start:dev`)
- Deploy your application (`npm run deploy`)
? Consider setting up Jenkins to continuously build your app.
Use `sap-cloud-sdk add-cx-server` to create the setup script.
+--------------------------------------------------------------+
# プロジェクトディレクトリに移動しstart:devを実行
$ cd node-sdk-chat && npm run start:dev
1:23:58 AM - Starting compilation in watch mode...
11:24:02 AM - Found 0 errors. Watching for file changes.
[Nest] 64793 - 02/13/2020, 11:24:02 AM [NestFactory] Starting Nest application...
[Nest] 64793 - 02/13/2020, 11:24:02 AM [InstanceLoader] AppModule dependencies initialized +15ms
[Nest] 64793 - 02/13/2020, 11:24:02 AM [RoutesResolver] AppController {/}: +4ms
[Nest] 64793 - 02/13/2020, 11:24:02 AM [RouterExplorer] Mapped {/, GET} route +2ms
[Nest] 64793 - 02/13/2020, 11:24:02 AM [NestApplication] Nest application successfully started +2ms
$ curl localhost:3000
Hello World!
$ nest g controller chat
CREATE /src/chat/chat.controller.spec.ts (479 bytes)
CREATE /src/chat/chat.controller.ts (97 bytes)
UPDATE /src/app.module.ts (322 bytes)
import { Controller, Get, Req, Post, Param } from '@nestjs/common';
import { Request } from 'express';
@Controller('chat')
export class ChatController {
@Get()
Reply(@Req() request: Request) {
//console.log(request)
console.log('Receive Get Request!!!!')
console.log('-----body-----')
console.log(request.body)
const test = {
"replies": [
{
"type": "quickReplies",
"content": {
"title": "Select Message Type",
"buttons": [
{
"title": "Button",
"value": "Show Buttonnest"
},
{
"title": "Picture",
"value": "Show Picture"
}
]
}
}]
}
;
return test
//return this.chatService.Reply();
};
@Post(':type')
ReplyPost(@Req() request: Request, @Param('type') type: string) {
console.log(type)
console.log('Receive Post Request!!!!')
console.log('-----body-----')
console.log(request.body)
var reply = { "replies": [] }
switch (type) {
case 'pict':
reply.replies.push(
{
"type": "picture",
"content": "https://www.sap.com/dam/application/shared/logos/sap-logo-svg.svg.adapt.svg/1493030643828.svg",
}
);
break;
case 'button':
reply.replies.push(
{
"type": "buttons",
"content": {
"title": "BUTTON_TITLE",
"buttons": [
{
"title": "BUTTON_TITLE",
"type": "BUTTON_TYPE",
"value": "BUTTON_VALUE"
}
]
}
});
break;
}
return reply
}
}
$ curl localhost:3000/chat
{"replies":[{"type":"quickReplies","content":{"title":"Select Message Type","buttons":[{"title":"Button","value":"Show Buttonnest"},{"title":"Picture","value":"Show Picture"}]}}]}
$ curl -X POST -H "Content-Type: application/json" -d '{"key": "value"}' localhost:3000/chat/pict
{"replies":[{"type":"picture","content":"https://www.sap.com/dam/application/shared/logos/sap-logo-svg.svg.adapt.svg/1493030643828.svg"}]}
"ci-package": "sap-cloud-sdk package && rm -r -f deployment/node_modules",
applications:
- name: node-sdk-chat
path: deployment/
buildpacks:
- nodejs_buildpack
memory: 256M
command: npm run start:prod
routes:
- route: <route>.eu10.hana.ondemand.com
$ npm run deploy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
25 | |
24 | |
16 | |
14 | |
10 | |
9 | |
9 | |
7 | |
7 | |
7 |