npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@botmatic/js-api-client

v1.0.4

Published

A botmatic API Client implementing the External API Consumer interface to communicate with Botmatic Public API. It is meant to be used internally by the `js-contact` module, alongside `js-integration`.

Downloads

6

Readme

JS API Client

A botmatic API Client implementing the External API Consumer interface to communicate with Botmatic Public API.
It is meant to be used internally by the js-contact module, alongside js-integration.

Installation

npm install @botmatic/js-api-client --save

Basic Usage

const jsApiClient = require('js-api-client')()

// ...

const {success, id, error} = jsApiClient.createContact(contact, token)

Authentication

All functions take a token as last argument. You can obtain such Token following the installation procedure with the js-integration module.

Call returns

All functions return Promises resolving to an object with the following properties:

property | type | description -------- | ---------------- | ----------- success | boolean | true if the call is successful, false in case of error error | string or object | only if success == false an error description ... | any | only if success == true function specific returned data

Contacts API

The js-api-client module allows you to create, update or delete contacts.

Contact objects

On Botmatic, you can manage which properties a contact has. Contact objects should have any of these properties.
See the properties API below and the js-mapper module to learn how to create contacts you can import into Botmatic

createContact(contact, token) -> {success, id, error}

Sends a request to the Botmatic API to create a contact. The Botmatic id of the created contact is return in the object the Promise resolves to.

Example
// using Promises
jsApiClient.createContact(contact, token)
  .then(({success, id, error}) => {
    // id is the Botmatic id for the created contact
  })
  
// using async / await
const {success, id, error} = await jsApiClient.createContact(contact, token)
// id is the Botmatic id for the created contact

createContacts(contacts, token) -> {success, contacts, error}

Sends a request to the Botmatic API to create many contacts at once. The Botmatic ids of the created contacts are returned in the object the Promise resolves to.

Retrieving the created ids

The object the Promise resolves to has a contacts property containing the ids for each created contact.
It is an array of {success, id, error} objects. It preserves the order of contacts in the array passed as the contacts arguments.

Example
// using Promises
jsApiClient.createContacts(contacts, token)
  .then(({success, contacts, error}) => {
    // contacts == [{success: true, id: 23}, {success: true, id: 24}, {success: false, id: 25}, ...]
  })
  
// using async / await
const {success, contacts, error} = await jsApiClient.createContact(contact, token)
// contacts == [{success: true, id: 23}, {success: true, id: 24}, {success: false, id: 25}, ...]
Example
const sent_contacts = [
  { "id": 978, "firstname": "Patrick" }, // external id == 978
  { "id": 979, "firstname": "Mickael"}   // external id == 979
]

const {success, contacts, error} = await jsApiClient.createContacts(sent_contacts, token)
// success == true, contacts is an array of {success, id, error} objects
// 

// iterate over the sent contacts to find their botmatic id
const created_contacts = sent_contacts.map((sent_contact, index) => {
  const {success, id, error} = contacts[index]
  
  if (success) {
      const externalId = sent_contact.id
      const botmaticId = id
      
      // You can store the botmatic/external id using a module implementing the KeyStore interface
      keyStore.saveIds(integrationId, botmaticId, externalId)
  }
  else {
    // Handle the error
  }
})

updateContact(contact, token) -> {success, error}

Sends a request to the Botmatic API to update a contact.
The contact id property must be present and contain an existing id on Botmatic's side.

Example
// using Promises
jsApiClient.updateContact(contact, token)
  .then(({success, error}) => {
    // ...
  })
  
// using async / await
const {success, error} = await jsApiClient.updateContact(contact, token)

deleteContact(id, token) -> {success, error}

Sends a request to the Botmatic API to delete a contact.
The id parameter must be an existing id on Botmatic's side.

Example
// using Promises
jsApiClient.deleteContact(id, token)
  .then(({success, error}) => {
    // ...
  })
  
// using async / await
const {success, error} = await jsApiClient.deleteContact(id, token)

Properties API

The js-api-client allows you to create one or several properties on your Botmatic workspace.

The Property object

{
  "name": "firstname",
  "type": "text"
}

type can be "text", "number" or `"date"

createProperty(property, token) -> Promise<{success, error}>

Creates a property on Botmatic.

Example
// using Promises
jsApiClient.createProperty({name: "firstname", type:"text"}, TOKEN)
  .then(({success, error}) => {
    // ...
  })

// using async/await
const {success, error} = await jsApiClient.createProperty({name: "firstname", type:"text"}, TOKEN)

createProperties(properties, token) -> Promise<{success, error}>

Creates many properties on Botmatic.

Example
// using Promises
jsApiClient.createProperties(properties, TOKEN)
  .then(({success, error}) => {
    // ...
  })

// using async/await
const {success, error} = await jsApiClient.createProperties(properties, TOKEN)