SDK
Chatness provides official SDKs for the Node
and Browser
platforms. You can use these SDKs to integrate Chatness into any kind of application and whenever you are on a different platform, you can use our REST API endpoints directly. We provide examples for every endpoint in the documentation, but if you need help, feel free to contact us.
Install
You can install the Chatness SDK using npm
or any other package manager.
To work in the browser, you can install the SDK using:
npm install @chatness/browser
To work in the server, you can install the SDK using:
npm install @chatness/server
You can also use the SDK with Typescript and get full-type support. The SDKs are actually written in Typescript and bundled for esm
and cjs
usage.
Examples
const { Chatness } = require('@chatness/server')
const orgToken = 'your-org-token';
const botId = 'your-bot-id';
const chat = new Chatness({
orgToken
});
// create a token
const { data } = await chat.auth
.contacts({ botId })
.create({
email: '[email protected]'
});
const { token } = data;
// pass down the contact token
// to your frontend application
console.log(token);
Browser Methods
Here is a list of the different methods available in the SDK for browser:
Auth Contacts Login
Login a contact using the authorization token.
chat.auth.contacts.login({ ...payload })
Payload
- Name
token
- Type
- string
- Description
The contact token is obtained from the server for browser authorization.
Auth Contacts Logout
Logout the current contact.
chat.auth.contacts.logout()
Widget Open
Open the widget to start new conversations.
chat.widget.open()
Widget Close
Close the widget but keep the launcher visible.
chat.widget.close()
Widget Hide
Completely hide the widget. The launcher won't be shown.
chat.widget.hide()
Widget Show
Show the widget launcher.
chat.widget.show()
Widget Message
Send a message to the current conversation.
chat.widget.message({ ...payload })
Payload
- Name
text
- Type
- string
- Description
The text message to send.
Server Methods
Here is a list of the different methods available in the SDK for server:
Auth Contacts Tokenize
Generate a contact authorization token.
chat.auth.contacts.tokenize({ ...payload })
Payload
- Name
id
- Type
- string
- Description
- Name
email
- Type
- string
- Description
Either id
or email
should be provided.
Auth Contacts Revoke
Revoke a contact authorization token. Will logout the contact from all devices.
chat.auth.contacts.revoke({ ...payload })
Payload
- Name
contactToken
- Type
- string
- Description
Contacts Create
Create a new contact.
chat.contacts.create({ ...payload })
Payload
- Name
name
- Type
- string
- Description
- Name
email
- Type
- string
- Description
- Name
phone
- Type
- string
- Description
- Name
wid
- Type
- string
- Description
The WhatsApp ID when a conversation is started from the WhatsApp integration. You can also provide the WhatsApp ID when you create or update a contact. The WhatsApp ID is the phone number with the country code.
- Name
mid
- Type
- string
- Description
The Messenger ID when a conversation is started from the Messenger integration.
Contacts Upsert
Create or update contacts in bulk.
chat.contacts.upsert([{ ...payload }])
Payload
- Name
name
- Type
- string
- Description
- Name
email
- Type
- string
- Description
- Name
phone
- Type
- string
- Description
- Name
wid
- Type
- string
- Description
The WhatsApp ID when a conversation is started from the WhatsApp integration. You can also provide the WhatsApp ID when you create or update a contact. The WhatsApp ID is the phone number with the country code.
- Name
mid
- Type
- string
- Description
The Messenger ID when a conversation is started from the Messenger integration.
Contacts Search
Search for contacts by name, email, phone, id, mid, or wid.
chat.contacts.search({ ...payload })
Payload
- Name
query
- Type
- string
- Description
- Name
page
- Type
- number
- Description
- Name
limit
- Type
- number
- Description
Contacts Retrieve
Retrieve a contact by its ID.
chat.contacts.retrieve(contactId)
- Name
contactId
- Type
- string
- Description
Contacts Update
Update a contact by its ID.
chat.contacts.update(contactId, payload)
- Name
contactId
- Type
- string
- Description
Payload
- Name
name
- Type
- string
- Description
- Name
email
- Type
- string
- Description
- Name
phone
- Type
- string
- Description
- Name
wid
- Type
- string
- Description
The WhatsApp ID when a conversation is started from the WhatsApp integration. You can also provide the WhatsApp ID when you create or update a contact. The WhatsApp ID is the phone number with the country code.
- Name
mid
- Type
- string
- Description
The Messenger ID when a conversation is started from the Messenger integration.
Contacts Delete
Delete a contact by its ID.
chat.contacts.delete(contactId)
- Name
contactId
- Type
- string
- Description