diff --git a/src/api/chatting.controller.ts b/src/api/chatting.controller.ts index dd00194e..1da924b7 100644 --- a/src/api/chatting.controller.ts +++ b/src/api/chatting.controller.ts @@ -11,15 +11,7 @@ import { MessageText } from "./all.dto"; import {Whatsapp} from "venom-bot"; - -const SUFFIX_DIRECT_MESSAGE = "@c.us" - -function ensureSuffix(phone){ - if (phone.endsWith(SUFFIX_DIRECT_MESSAGE)){ - return phone - } - return phone + SUFFIX_DIRECT_MESSAGE -} +import {ensureSuffix} from "../whatsapp.service"; @Controller('api') @ApiTags('chatting') diff --git a/src/whatsapp.service.ts b/src/whatsapp.service.ts index 6af3d0a3..e90541e5 100644 --- a/src/whatsapp.service.ts +++ b/src/whatsapp.service.ts @@ -1,5 +1,5 @@ import {create, Message, Whatsapp} from "venom-bot"; -import {ConsoleLogger, Inject, Injectable, Logger, OnApplicationShutdown} from "@nestjs/common"; +import {ConsoleLogger, Inject, Injectable, OnApplicationShutdown} from "@nestjs/common"; import {ConfigService} from "@nestjs/config"; import * as path from "path"; import {WhatsappConfigService} from "./config.service"; @@ -169,3 +169,16 @@ export class WhatsappService implements OnApplicationShutdown { } } + +const SUFFIX_DIRECT_MESSAGE = "@c.us" + +/** + * Add WhatsApp suffix (@c.us) to the phone number if it doesn't have it yet + * @param phone + */ +export function ensureSuffix(phone) { + if (phone.endsWith(SUFFIX_DIRECT_MESSAGE)) { + return phone + } + return phone + SUFFIX_DIRECT_MESSAGE +}