Creating your first customer

Now that you have a connected client, we can create our first customer. To create a customer, you need to provide a customerNumber. A customerNumber has the type of channel the number belongs to and the number itself. So let's make our first customer with a cellular channel; other channels include telegram, facebook, email, and app.

const client = new Elarian({
    orgId: 'your-org-id',
    appId: 'your-app-id',
    apiKey: 'your-api-key'
});
ā€‹
async function onConnected() {
  console.log('App is running!');

  const alice = new client.Customer({
    number: '+254712345678',
    provider: 'cellular'
  });
}

client
    .on('error', (err) => console.error(`Connnection error: ${err}`))
    .on('connected', onConnected)
    .connect();

Sending your first command

At this point, Elarian has created a new customer entity that doesn't have any data. Next, let's interact with the programmable customer object and issue our first command.

const client = new Elarian({
    orgId: 'your-org-id',
    appId: 'your-app-id',
    apiKey: 'your-api-key'
});
ā€‹
async function onConnected () {
  console.log('App is running!');

  const alice = new client.Customer({
    number: '+254712345678',
    provider: 'cellular'
  });

  await alice.updateMetadata({ name: 'Alice' });

  const state = await alice.getState();
  console.log(state);
}

client
    .on('error', (err) => console.error(`Connnection error: ${err}`))
    .on('connected', onConnected)
    .connect();

The code sample above actually uses two commands, the first is updateMetadata and the second is getState which returns all of the customer's state. Commands are asynchronous as there's an underlying network call made to the Elarian service.