Skip to content

MQ-SMS Integration

@nx/mq-sms is a multi-provider SMS management library. It wraps SMS provider APIs behind a unified interface with a client registry pattern. Currently supports VnPay as the sole SMS provider.

Quick Reference

PropertyValue
Package@nx/mq-sms
Locationthird-parties/mq-sms/
TypeLibrary (consumed as a component by other services)
Consumed by@nx/identity (OTP delivery)

Architecture

Providers

ProviderCodeStatus
VnPayMQSMSProviders.VNPAY = 'vnpay'Active

VnPay Configuration

FieldPurpose
username / passwordAPI authentication
partnerCode / secretKeyPartner identification
keywordSMS keyword/brand name
brandNameSender display name
encryptIvIV for encrypted SMS mode (optional)
partnerPrivateKeyPathRSA private key for security mode (optional)

VnPay endpoints used:

  • /login — authentication (auto-managed by client)
  • /send-sms — single SMS
  • /v2/send-sms-security — encrypted single SMS
  • /send-sms-list — batch SMS
  • /v2/send-sms-list-security — encrypted batch SMS

SMSService

Core service methods:

MethodPurpose
sendSMS(request, clientName?)Send single SMS via the default or named client
sendSMSSecurity(request, clientName?)Send single encrypted SMS
sendSMSList(requests, clientName?)Send batch SMS
sendSMSListSecurity(requests, clientName?)Send batch encrypted SMS

Request format

typescript
interface TSendSmsRequest {
  messageId?: string;     // optional correlation ID
  destination: string;    // phone number
  content: string;        // message body
}

MQSMSClientRegistryService

Manages multiple provider client instances:

MethodPurpose
registerClient(name, client)Register a provider client
unregisterClient(name)Remove a client
getClient(name?)Get client by name (or default)
getDefaultClient()Get the current default client
setDefaultClient(name)Switch the default client

Each registered client tracks: token, token expiry, last used timestamp.

REST Controller (Optional)

When enableControllers: true is set in MQSMSComponent options, an SMSController is registered:

MethodPathPurpose
POST/mq-sms/sms/sendSend single SMS
POST/mq-sms/sms/send-securitySend encrypted SMS
POST/mq-sms/sms/send-listSend batch SMS
POST/mq-sms/sms/send-list-securitySend batch encrypted SMS

All endpoints accept an optional clientName query parameter to select a specific provider client.

Integration with Identity

The identity service uses MQ-SMS for OTP (One-Time Password) delivery:

  1. SMSComponent in identity registers MQSMSComponent at startup
  2. Provider configs are loaded from the database (seeded by identity-0006-seed-sms-configurations)
  3. SMSOTPSender injects SMSService and calls sendSMS() to deliver verification codes
  4. SMS configs support multiple VnPay clients (different brand names/accounts)

Binding Keys

KeyPurpose
MQSMSBindingKeys.MQ_SMS_CLIENT_OPTIONSComponent configuration
MQSMSBindingKeys.MQ_SMS_CLIENT_PROVIDERClient factory function
MQSMSBindingKeys.MQ_SMS_CLIENT_REGISTRYRegistry service instance

VnPay Response Codes

CodeMeaning
00Success
02Invalid length
04Invalid authentication
05Provider disconnected
06IP not registered
21Insufficient balance
85Invalid sender
86Invalid keyword
90Duplicate message
PageDescription
Identity — AuthenticationOTP delivery via MQ-SMS
MQ-PayMulti-provider payment (similar registry pattern)

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.