platformclient/ts/email/classes.smsconnector.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-02-17 19:24:28 +00:00
import type { SzPlatformClient } from '../classes.platformclient.js';
import { logger } from '../logger.js';
2024-02-17 19:24:28 +00:00
import * as plugins from '../plugins.js';
export class SzSmsConnector {
public platformClientRef: SzPlatformClient;
constructor(platformClientRefArg: SzPlatformClient) {
this.platformClientRef = platformClientRefArg;
}
public async sendSms(messageArg: plugins.servezoneInterfaces.platformservice.sms.IRequest_SendSms['request']) {
if (this.platformClientRef.debugMode) {
logger.log('info', `sent sms to ${messageArg.toNumber}}
body:
${messageArg.messageText.split('\n').map(line => ` ${line}`).join('\n')}
`);
}
if (this.platformClientRef.debugMode) {
return;
}
const typedrequest = this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.sms.IRequest_SendSms>(
'sendSms'
);
const response = await typedrequest.fire(messageArg);
2024-02-17 19:24:28 +00:00
return response.status;
}
public async sendSmsVerifcation(
recipientArg: plugins.servezoneInterfaces.platformservice.sms.IRequest_SendVerificationCode['request']
) {
if (this.platformClientRef.debugMode) {
console.log('sendSmsVerifcation', recipientArg, '123456');
return '123456';
}
2024-02-17 19:24:28 +00:00
const typedrequest =
this.platformClientRef.typedsocket.createTypedRequest<plugins.servezoneInterfaces.platformservice.sms.IRequest_SendVerificationCode>(
'sendVerificationCode'
);
const response = await typedrequest.fire(recipientArg);
return response.verificationCode;
}
}