-
Notifications
You must be signed in to change notification settings - Fork 4
Transactions
Here are two ways to work with transactions : default or custom.
Most part of time, default transactions are suffisant, but if you have a specific need you can define your own transactions.
Note that the default compiler is not available with custom transactions. In other terms, i you wish define your own transactions, you will compile yourself your templates, or delegate the compilation to your API provider.
There transactions working with any mode (api|smtp), and any compiler (provider|self|default).
The example payloads shown here are strictly required if you want to use the default build. If you compile your templates yourself or delegate the compilation to your API provider, you are obviously free to adapt these payloads to your needs.
He's used as fallback when you fire a non existing transaction, or intentionaly when you fire 'default'. This is useful if the message you need to send is short and conventional.
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired when a user subscribe to an event.
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired when a user unsubscribe from an event.
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired when an event is updated.
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Can be fired when a user close her account
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired when a user must confirm her subscription.
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired when a user contact you, or when you contact a user.
{
from: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired when a user invite another user.
{
from: {
username: String,
email: String,
picture?: String
},
message: String,
cta: {
label: String,
link: String
}
}
Can be fired at each step of a complexe registration process.
{
progress: Number,
cta: {
label: String,
link: String
}
}
Can be fired when you wish ask an opinion about a particular subject.
{
sentence: String,
uri: String
}
Should be fired when a user has confirmed her subscription
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired when you send an invoice to the customer.
{
customer: {
name: String,
street: String,
zip: String,
city: String,
country: String,
vat_number: String
},
order: {
date: Date,
reference: String
},
invoice: {
without_vat: Number,
vat_percentage: Number,
vat_amount: Number,
total: Number,
currency: String
},
cta: {
label: String,
link: String
}
}
Should be fired when an order pass a step in your shipping process.
{
order: {
date: Date,
reference: String,
progress: Number
},
cta: {
label: String,
link: String
}
}
Should be fired when the order has been delivered.
{
customer: {
name: String,
street: String,
zip: String,
city: String,
country: String,
vat_number: String
},
order: {
date: Date,
reference: String
},
cta?: {
label: String,
link: String
}
}
Should be fired when a user request a new password (typicaly when he's forgotten her password).
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
Should be fired as confirmation when user have modified her password.
{
user: {
username: String,
email: String
},
message: String,
cta: {
label: String,
link: String
}
}
The default compiler is not available with custom transactions. You will compile yourself your templates, or delegate the compilation to your API provider.
Map your template
If you compile yourself your template, skip this step.
Else, in cliamrc.js, as option of your transporter, add a template entry for your transaction:
{
"options": {
"templates": {
"my.custom.transaction": "template-id"
}
}
}
Fire transaction and send email:
import { Cliam } from 'cliam';
// Do some stuffs ...
Cliam.mail('my.custom.event', data)
.then(res => {
console.log('Email has been delivered: ', res);
})
.catch(err => {
console.log('Error while mail sending: ', err)
});