diff --git a/apps/question-service/src/dto/QuestionResult.ts b/apps/question-service/src/dto/QuestionResult.ts new file mode 100644 index 0000000..2cbe5ff --- /dev/null +++ b/apps/question-service/src/dto/QuestionResult.ts @@ -0,0 +1,4 @@ +export class QuestionResult { + label: 'QUESTION' | 'STATEMENT'; + score: number; +} diff --git a/apps/question-service/src/dto/QuestionText.ts b/apps/question-service/src/dto/QuestionText.ts new file mode 100644 index 0000000..acdd5d9 --- /dev/null +++ b/apps/question-service/src/dto/QuestionText.ts @@ -0,0 +1,3 @@ +export class QuestionText { + text: string; +} diff --git a/apps/question-service/src/question-service.controller.ts b/apps/question-service/src/question-service.controller.ts index da199cb..09a5827 100644 --- a/apps/question-service/src/question-service.controller.ts +++ b/apps/question-service/src/question-service.controller.ts @@ -11,9 +11,10 @@ export class QuestionServiceController { ) { } @MessagePattern(UpdateEvent.MESSAGE) - async message(@Payload() data): Promise { - const { update } = data; + async message(@Payload() payload): Promise { + const { update } = payload; const { message } = update; - this.logger.log('Message received', message); + const { data } = await this.questionServiceService.test(message.text); + this.logger.log('Result', data); } } diff --git a/apps/question-service/src/question-service.module.ts b/apps/question-service/src/question-service.module.ts index 5d1d516..8a40d93 100644 --- a/apps/question-service/src/question-service.module.ts +++ b/apps/question-service/src/question-service.module.ts @@ -3,6 +3,7 @@ import { QuestionServiceController } from './question-service.controller'; import { QuestionServiceService } from './question-service.service'; import { schemaConfig, rmqConfig, mongoConfig, RmqModule } from '@app/common'; import { ConfigModule } from '@nestjs/config'; +import { HttpModule } from '@nestjs/axios'; @Module({ imports: [ @@ -12,6 +13,7 @@ import { ConfigModule } from '@nestjs/config'; isGlobal: true, }), RmqModule, + HttpModule, ], controllers: [QuestionServiceController], providers: [QuestionServiceService], diff --git a/apps/question-service/src/question-service.service.ts b/apps/question-service/src/question-service.service.ts index 4d951b1..e675edd 100644 --- a/apps/question-service/src/question-service.service.ts +++ b/apps/question-service/src/question-service.service.ts @@ -1,8 +1,18 @@ +import { HttpService } from '@nestjs/axios'; import { Injectable } from '@nestjs/common'; +import { QuestionResult } from './dto/QuestionResult'; +import { AxiosResponse } from 'axios'; @Injectable() export class QuestionServiceService { - getHello(): string { - return 'Hello World!'; + constructor(private readonly httpService: HttpService) { } + + test(text: string): Promise> { + return this.httpService.axiosRef.post( + 'http://telegram-question-service-ext-1/test', + { + text, + }, + ); } } diff --git a/docker-compose.yml b/docker-compose.yml index 64af320..da890ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -89,6 +89,12 @@ services: container_name: telegram-question command: npm run start question-service + question-service-ext: + image: ghcr.io/togethercrew/question-service:main + platform: linux/x86_64 + ports: + - 80:80 + volumes: mongo_data: neo4j_data: diff --git a/package-lock.json b/package-lock.json index aa503e6..cfd48dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.1", "license": "UNLICENSED", "dependencies": { + "@nestjs/axios": "^3.0.3", "@nestjs/common": "^10.3.3", "@nestjs/config": "^3.2.0", "@nestjs/core": "^10.3.3", @@ -17,6 +18,7 @@ "@nestjs/platform-express": "^10.3.3", "amqp-connection-manager": "^4.1.14", "amqplib": "^0.10.3", + "axios": "^1.7.7", "grammy": "^1.22.4", "joi": "^17.12.2", "mongoose": "^8.2.0", @@ -1650,6 +1652,16 @@ "sparse-bitfield": "^3.0.3" } }, + "node_modules/@nestjs/axios": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@nestjs/axios/-/axios-3.0.3.tgz", + "integrity": "sha512-h6TCn3yJwD6OKqqqfmtRS5Zo4E46Ip2n+gK1sqwzNBC+qxQ9xpCu+ODVRFur6V3alHSCSBxb3nNtt73VEdluyA==", + "peerDependencies": { + "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0", + "axios": "^1.3.1", + "rxjs": "^6.0.0 || ^7.0.0" + } + }, "node_modules/@nestjs/cli": { "version": "10.3.2", "resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-10.3.2.tgz", @@ -3031,8 +3043,17 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } }, "node_modules/babel-jest": { "version": "29.7.0", @@ -3670,7 +3691,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -3988,7 +4008,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -4864,6 +4883,25 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/foreground-child": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", @@ -4934,7 +4972,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -7465,6 +7502,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/package.json b/package.json index a00a6dc..aee47c8 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "test:e2e": "jest --config ./apps/telegram/test/jest-e2e.json" }, "dependencies": { + "@nestjs/axios": "^3.0.3", "@nestjs/common": "^10.3.3", "@nestjs/config": "^3.2.0", "@nestjs/core": "^10.3.3", @@ -28,6 +29,7 @@ "@nestjs/platform-express": "^10.3.3", "amqp-connection-manager": "^4.1.14", "amqplib": "^0.10.3", + "axios": "^1.7.7", "grammy": "^1.22.4", "joi": "^17.12.2", "mongoose": "^8.2.0", @@ -83,4 +85,4 @@ "^@app/common(|/.*)$": "/libs/common/src/$1" } } -} \ No newline at end of file +}