Skip to main content

Quik Framework :: Communication

@quik/communication provides pluggable email, SMS, and WhatsApp engines.

Installation

pnpm add @quik/communication

Configuration

Email (communication.email)

  • enabled from COMMUNICATION_EMAIL_ENABLED.
  • engine from COMMUNICATION_EMAIL_ENGINE default test.
  • from from COMMUNICATION_EMAIL_FROM default quikland@localhost.
  • config.address from COMMUNICATION_EMAIL_ADDRESS.
  • config.password from COMMUNICATION_EMAIL_PASSWORD.
  • config.server from COMMUNICATION_EMAIL_SERVER default localhost.
  • config.port from COMMUNICATION_EMAIL_PORT default 25.
  • config.secure from COMMUNICATION_EMAIL_SECURE.
  • timeoutMilliseconds from COMMUNICATION_EMAIL_TIMEOUT_MILLISECONDS.
  • retry.attempts from COMMUNICATION_EMAIL_RETRY_ATTEMPTS.
  • retry.delayMilliseconds from COMMUNICATION_EMAIL_RETRY_DELAY_MILLISECONDS.
  • retry.backoffFactor from COMMUNICATION_EMAIL_RETRY_BACKOFF_FACTOR.

SMS (communication.sms)

  • enabled from COMMUNICATION_SMS_ENABLED.
  • from from COMMUNICATION_SMS_FROM.
  • engine from COMMUNICATION_SMS_ENGINE default test.
  • config.clientIdentifier from COMMUNICATION_SMS_CLIENT_IDENTIFIER.
  • config.clientSecret from COMMUNICATION_SMS_CLIENT_SECRET.
  • timeoutMilliseconds from COMMUNICATION_SMS_TIMEOUT_MILLISECONDS.
  • retry.attempts from COMMUNICATION_SMS_RETRY_ATTEMPTS.
  • retry.delayMilliseconds from COMMUNICATION_SMS_RETRY_DELAY_MILLISECONDS.
  • retry.backoffFactor from COMMUNICATION_SMS_RETRY_BACKOFF_FACTOR.

WhatsApp (communication.whatsapp)

  • enabled from COMMUNICATION_WHATSAPP_ENABLED.
  • from from COMMUNICATION_WHATSAPP_FROM.
  • engine from COMMUNICATION_WHATSAPP_ENGINE default test.
  • config.accessToken from COMMUNICATION_WHATSAPP_ACCESS_TOKEN.
  • config.phoneNumberIdentifier from COMMUNICATION_WHATSAPP_PHONE_NUMBER_IDENTIFIER.
  • config.graphApiVersion from COMMUNICATION_WHATSAPP_GRAPH_API_VERSION default v22.0.
  • timeoutMilliseconds from COMMUNICATION_WHATSAPP_TIMEOUT_MILLISECONDS.
  • retry.attempts from COMMUNICATION_WHATSAPP_RETRY_ATTEMPTS.
  • retry.delayMilliseconds from COMMUNICATION_WHATSAPP_RETRY_DELAY_MILLISECONDS.
  • retry.backoffFactor from COMMUNICATION_WHATSAPP_RETRY_BACKOFF_FACTOR.

Register And Use Engines

Email attachments

IQEmailOptions.attachments accepts file paths or QEmailAttachment objects for inline content:

import { EmailEngineStore, type QEmailAttachment } from '@quik/communication';

await EmailEngineStore.get('nodemailer').send({
to: 'user@example.com',
subject: 'Report',
text: 'See attached.',
attachments: [
'/tmp/report.pdf', // file path
{ // inline buffer
filename: 'data.csv',
content: Buffer.from('a,b\n1,2'),
contentType: 'text/csv'
} satisfies QEmailAttachment
]
});

Custom email engine

import {
EmailEngineStore,
QEmailEngine,
QEmailEngineType,
type IQEmailOptions
} from '@quik/communication';

class ConsoleEmailEngine extends QEmailEngine {
protected get transportType() {
return QEmailEngineType.TEST;
}

protected async _send(message: IQEmailOptions) {
console.log('Email subject:', message.subject);
}
}

EmailEngineStore.add('console', ConsoleEmailEngine);
await EmailEngineStore.get('console').send({
to: 'user@example.com',
subject: 'Welcome',
text: 'Hi there.'
});

WhatsApp Message Builders

Use WhatsAppMessages to build typed payloads for supported message types:

  • text.
  • template.
  • image.
  • video.
  • audio.
  • document.
  • sticker.
  • location.
  • reaction.
import { WhatsAppEngineStore, WhatsAppMessages } from '@quik/communication';

const msg = WhatsAppMessages.template('40700111222', {
name: 'otp_code',
language: { code: 'en' },
components: [
{
type: 'body',
parameters: [ { type: 'text', text: '123456' } ]
}
]
});

await WhatsAppEngineStore.get('meta').send(msg);

API Reference

Generated API documentation is available in the communication API section.