Quik Framework :: Communication
- Codename: Berlin
- Version: 0.2.0-beta.76
- License: Check license here
@quik/communication provides pluggable email, SMS, and WhatsApp engines.
Installation
pnpm add @quik/communication
Configuration
Email (communication.email)
enabledfromCOMMUNICATION_EMAIL_ENABLED.enginefromCOMMUNICATION_EMAIL_ENGINEdefaulttest.fromfromCOMMUNICATION_EMAIL_FROMdefaultquikland@localhost.config.addressfromCOMMUNICATION_EMAIL_ADDRESS.config.passwordfromCOMMUNICATION_EMAIL_PASSWORD.config.serverfromCOMMUNICATION_EMAIL_SERVERdefaultlocalhost.config.portfromCOMMUNICATION_EMAIL_PORTdefault25.config.securefromCOMMUNICATION_EMAIL_SECURE.timeoutMillisecondsfromCOMMUNICATION_EMAIL_TIMEOUT_MILLISECONDS.retry.attemptsfromCOMMUNICATION_EMAIL_RETRY_ATTEMPTS.retry.delayMillisecondsfromCOMMUNICATION_EMAIL_RETRY_DELAY_MILLISECONDS.retry.backoffFactorfromCOMMUNICATION_EMAIL_RETRY_BACKOFF_FACTOR.
SMS (communication.sms)
enabledfromCOMMUNICATION_SMS_ENABLED.fromfromCOMMUNICATION_SMS_FROM.enginefromCOMMUNICATION_SMS_ENGINEdefaulttest.config.clientIdentifierfromCOMMUNICATION_SMS_CLIENT_IDENTIFIER.config.clientSecretfromCOMMUNICATION_SMS_CLIENT_SECRET.timeoutMillisecondsfromCOMMUNICATION_SMS_TIMEOUT_MILLISECONDS.retry.attemptsfromCOMMUNICATION_SMS_RETRY_ATTEMPTS.retry.delayMillisecondsfromCOMMUNICATION_SMS_RETRY_DELAY_MILLISECONDS.retry.backoffFactorfromCOMMUNICATION_SMS_RETRY_BACKOFF_FACTOR.
WhatsApp (communication.whatsapp)
enabledfromCOMMUNICATION_WHATSAPP_ENABLED.fromfromCOMMUNICATION_WHATSAPP_FROM.enginefromCOMMUNICATION_WHATSAPP_ENGINEdefaulttest.config.accessTokenfromCOMMUNICATION_WHATSAPP_ACCESS_TOKEN.config.phoneNumberIdentifierfromCOMMUNICATION_WHATSAPP_PHONE_NUMBER_IDENTIFIER.config.graphApiVersionfromCOMMUNICATION_WHATSAPP_GRAPH_API_VERSIONdefaultv22.0.timeoutMillisecondsfromCOMMUNICATION_WHATSAPP_TIMEOUT_MILLISECONDS.retry.attemptsfromCOMMUNICATION_WHATSAPP_RETRY_ATTEMPTS.retry.delayMillisecondsfromCOMMUNICATION_WHATSAPP_RETRY_DELAY_MILLISECONDS.retry.backoffFactorfromCOMMUNICATION_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.