Customer State

Learn how customer state helps you build scalable customer engagement applications on the Elarian Framework.

Customer state contains the records of everything your application has done with a customer. This includes your most recent interactions with the customer as well as any other additional state your application would like to track.

Here are all the possible customer state entries:

  1. customerId - A unique identifier generated by Elarian
  2. messagingState - All communication engagements between your application and a customer e.g sms messages, ussd sessions e.t.c
  3. paymentState - All payment engagements between your application and a customer e.g payments sent, collected e.t.c
  4. activityState - All activity engagements tracked by your application for a customer e.g web/mobile session data
  5. identityState - Non engagement related state belonging to the customer e.g secondaryIds, reminders, metadata e.t.c

Get customer state

const customer = new client.Customer({
    number: 'YOUR-CUSTOMERS-PHONE-NUMBER',
    provider: 'cellular'
});

const customerState = await customer.getState();

/*
{
  customerId: '...',
  messagingState: [...],
  paymentState: [...],
  activityState: [...],
  identitiyState: {...}
}
*/
console.log(customerState);

Adopt customer state

If you have interacted with the same customer across different communication channels, you can merge the two customer entities within Elarian into one customer. This will adopt all of the state from customer B into customer A and discard customer B.

const customerA = new client.Customer({...});

const customerB = new client.Customer({...});

const res = await customerA.adoptState(customerB);

console.log(res);