ChatDaddy allows users to build scalable tools for businesses to empower their users to communicate via WhatsApp at the cheapest rates starting at just 1 USD/mo! For businesses to offer great services at affordable rates, they’d need access to an API that enables them to quickly add/remove users based on the requirements for each individual user.
For example, some users of your product may not require chat history and only send 500 messages a month whereas others send over 10000 messages a month!
This guide covers how to build a scalable platform using ChatDaddy’s APIs, that accommodates the usage of individual users. This is of course, in addition to all the features you get with the API, such as:
Before you can start building your scalable platform with the API, let’s get you access to the full platform
Register for a ChatDaddy account if you haven’t already from https://app.chatdaddy.tech/SignUp
Open ChatDaddy
Click the “Upgrade Subscription” button
Purchase the “API” plan
Continue to payment
Enter your card details & finish the purchase
You should be redirected back to ChatDaddy & see a “Successful Purchase” popup
Refresh the page now and verify that you the newly purchased plan in the billing section like the image below
Superb! Now that you’ve full access to the platform, let’s get started with the API. We’d recommend using our typescript/javascript client to interact with our instant messaging service or if you choose, you could write your own REST client as well.
For this guide, we’ll be using the typescript client from GitHub.
Let’s setup a project to use API client now:
yarn
too if you’d like) via npm init
npm i git+https://github.com/chatdaddy/typescript-client.git
src/index.js
Let’s authenticate
Inside index.js
— add the following snippet that’ll allow us to authenticate our requests
import { verifyToken, makeAccessTokenFactory, JWT, Scope } from '@chatdaddy/client'
const REFRESH_TOKEN = 'put-your-refresh-token-here'
const TEAM_ID = 'put-team-id'
// the access token factory fetches access tokens as you'd need them
// using your refresh token, so that you can easily make requests to our services
// without worrying about expired credentials or over-fetching access tokens
const getAccessToken = makeAccessTokenFactory({
request: { refreshToken: REFRESH_TOKEN }
})
If you don’t have a refresh token or don’t know your team ID, you can find it easily on the ChatDaddy web app: https://app.chatdaddy.tech/settings/api
Now, let’s purchase & add your first user’s account (note: this step will create a 1USD charge on your account)
We’ll use the AccountApi
from the instant messaging service to purchase & add this account:
import { AccountApi, AccountTier, AccountType, Configuration } from '@chatdaddy/client'
(async() => {
const { token: accessToken } = await getAccessToken(TEAM_ID)
const accountsApi = new AccountApi(new Configuration({ accessToken }))
const { data } = await accountsApi.accountsPost({
accountsPostRequest: {
// just a nickname -- does not need to be unique
// this is just for display purposes
nickname: 'My New Account',
// change the tier to upgrade/downgrade functionality
// this one gives only limited messages, and syncs no chat history
tier: AccountTier.LimitedMsgNoChatHistory,
type: AccountType.Wa
}
})
console.log(`purchases & created a new account with ID: "${data.accountId}"!`)
})()
Voila! You should now have another account in your team that you can assign to any one of your users!
You can repeat this process as many times to scale as your user base grows!
Impressed as you may be now, you likely have two questions now:
We’ll tackle both now.
First, let’s see how you can unsubscribe the account. We offer two ways:
You can delete the account, removing all user data & cancelling the subscription in the process, with a simple API request:
// account ID => the ID of the account you want to delete
await accountsApi.accountsDelete({ accountId })
You can “archive” the account, this will cancel your subscription for this account — logout the user from account, remove all synced data (will however, keep all notes & contacts)
// account ID => the ID of the account to archive
await accountsApi.accountsArchive({ accountId })
Second, let’s see how you can upgrade/downgrade accounts:
With one super simple API call, you can update the account’s tier
// upgrades the tier to "unlimited messages & chat history"
await accountsApi.accountsPatch({
accountId,
accountsPatchRequest: { tier: AccountTier.UnlimitedMsgChatHistory }
})
If you try to change the tier of an account when it’s already at the same tier — the request will fail with a 400 Bad Request status code
Policy on downgrading:
There we go, you’re now fully equipped to build a platform that can quickly & cheaply scale with your user base!