Contact

UaSDK. Contact

Your user's contact record; distinct from a channel, this represents a "user" within Airship, and may be named and have channels associated with it.

Constructor

new Contact()

Example
const sdk = await UA

// create a channel if one doesn't exist
const channelId = await sdk.channel.id()
if (!channelId) {
  await sdk.create()
}
// associate this channel with a named user
await sdk.contact.identify("my-cool-user")

Members

subscriptions :ScopedSubscriptionListManager

The subscription manager for this contact.

Type:
Example
// subscribe the contact to a list
await sdk.subscriptions.edit()
  .subscribe('cool-list', 'app')
  .apply()

Methods

(async) associateChannel(platform, channelId) → {Promise.<void>}

Associate an existing channel to the given contact.

Parameters:
Name Type Description
platform Platform

the platform

channelId string

the channel id

Returns:
Type:
Promise.<void>
Example
await sdk.contact.associateChannel(
  'email',
  'd8bd95a4-d63d-4d41-a301-550f26091cc1'
)

editAttributes() → {AttributeEditor}

Create an attribute editor for the current contact.

Returns:
Type:
AttributeEditor

an attribute editor

Example
const editor = contact.editAttributes()
await editor
  .set("my_attribute", "some_value")
  .remove("other_attribute")
  .apply()

editTags() → {TagEditor}

Create a tag editor for the current contact.

Returns:
Type:
TagEditor

a tag editor

Example
const editor = contact.editTags()
await editor
  .add("my_group", ["tag1", "tag2"])
  .remove("my_group", ["tag3"])
  .apply()

(async) identify(namedUserId) → {Promise.<void>}

Associates the contact with the given named user identifier.

Parameters:
Name Type Description
namedUserId string

identifier to apply to the channel

Fires:
Returns:
Type:
Promise.<void>

resolves if identifier was applied; rejects if it was unsuccessful.

(async) registerEmail(emailAddress, options) → {Promise.<void>}

Register an email channel to the contact.

Parameters:
Name Type Description
emailAddress

the email address to register

options

email registration options

Returns:
Type:
Promise.<void>
Example
await sdk.contact.registerEmail('someone@domain.example', {
  doubleOptIn: true,
})

(async) registerOpen(address, options) → {Promise.<void>}

Register an Open channel to the contact.

Parameters:
Name Type Description
address

address of the device to register

options

open registration opens

Returns:
Type:
Promise.<void>
Example
await sdk.contact.registerOpen('d8bd95a4-d63d-4d41-a301-550f26091cc1', {
  platformName: 'toaster',
})

(async) registerSms(msisdn, options) → {Promise.<void>}

Register an SMS channel to the contact.

Parameters:
Name Type Description
msisdn

mobile number (MSISDN) to register

options

SMS registration options

Returns:
Type:
Promise.<void>
Example
await sdk.contact.registerSms('15551231234', {
  senderId: '55555',
})

(async) reset() → {Promise.<void>}

Disassociate the web channel from its current contact, and create a new un-named contact.

Returns:
Type:
Promise.<void>

resolves if the reset was successful.

Events

conflict

The contact fires a conflict event when a conflicting operation has taken place, such as you naming a contact to a name that already exists within Airship. While this would still name the contact, you may have had attributes and tags that have been set which would conflict with the existing record.

So you may perform your own conflict resolution, we emit all available local data along with the conflict event.

Properties:
Name Type Description
ev.detail ConflictEvent

The known data about the contact prior to the conflict.

Example
contact.addEventListener('conflict', ev => {
  // perform conflict resolution
})