@thinkroman/api@0.0.9
This is a TypeScript client library for the Thinkroman API. It provides a convenient way to interact with various Thinkroman API endpoints, including WhatsApp templates, R2 storage, and ads.
Thinkroman API Client
This is a TypeScript client library for the Thinkroman API. It provides a convenient way to interact with various Thinkroman API endpoints, including WhatsApp templates, R2 storage, and ads.
Installation
Install the package using npm:
bunx jsr add @thinkroman/api deno add @thinkroman/api npx jsr add @thinkroman/api pnpm dlx jsr add @thinkroman/api yarn dlx jsr add @thinkroman/api
Usage
Import the Thinkroman
class and create an instance with your API key:
import { Thinkroman } from '@thinkroman/api'; const tr = new Thinkroman({ key: 'YOUR_API_KEY', });
WhatsApp Templates
The client provides methods for sending WhatsApp templates:
// Send appointment cancellation template to a patient const {result, error} = await tr.whatsapp.common.appointmentCancellationPatient({ // Template parameters }); // Send appointment confirmation template to a doctor const {result, error} = await tr.whatsapp.common.appointmentConfirmationDoctor({ // Template parameters }); // Send demo credentials template const {result, error} = await tr.whatsapp.trCare.demoCredentials({ // Template parameters }); // Send account confirmation template const {result, error} = await tr.whatsapp.trDatacenter.accountConfirmation({ // Template parameters });
R2 Storage
The client provides methods for interacting with R2 storage:
// Get a presigned upload URL const {result, error} = await tr.storage.r2.uploadUrl({ // Query parameters }); // Get a public URL for an object const {result, error} = await tr.storage.r2.publicUrl({ // Query parameters }); // Get a signed URL for an object const {result, error} = await tr.storage.r2.signedUrl({ // Query parameters }); // Delete an object const {result, error} = await tr.storage.r2.delete({ // Query parameters });
Ads
The client provides a method for listing ads:
// List ads const result = await tr.ads.listAds({ // Query parameters });
To update the README with the provided parameter type, you can modify the markdown content as follows:
Rate Limiting
The client provides a method for rate limiting:
// Apply rate limiting const {result, error} = await tr.ratelimit.limit({ identifier: "user123", tokens: 10, duration: "1m", namespace: "trcare.openai", cost: 1, });
The limit
method takes an object with the following parameters:
identifier
(required): The unique identifier for the rate limiter.tokens
(required): The maximum number of tokens allowed within the duration.duration
(required): The duration of the rate limiting window, specified as aDuration
string.namespace
(required): The namespace for the rate limiter.cost
(optional): The cost per request. Defaults to1
.
The duration
parameter is of type Duration
, which represents a duration in a human-readable format. It can be a string in the format of "<number> <unit>"
or "<number><unit>"
, where <number>
is a numeric value and <unit>
is one of the following:
ms
: millisecondss
: secondsm
: minutesh
: hoursd
: days
For example, valid Duration
strings include:
"100ms"
"1s"
"5 m"
"2h"
"7d"
The limit
method returns a Result
object containing the rate limiting information or an error if the rate limit is exceeded.
In this updated version, the parameter type is reflected in the documentation, specifying that the duration
parameter is of type Duration
and providing examples of valid duration strings.
The other parameters (identifier
, tokens
, namespace
, and cost
) are also documented based on the provided parameter type.
You can replace the previous rate limiting section in your README with this updated markdown content.
Error Handling
The client returns a Result
object for each API call. It contains either a result
property with the successful response data or an error
property with error details.
You can handle errors like this:
const {result, error} = await tr.whatsapp.common.appointmentCancellationPatient({ // Template parameters }); if (error) { // Handle the error console.error(error); } else { // Access the result data console.log(result); }
Configuration
The Thinkroman
constructor accepts an options object with the following properties:
key
(required): Your Thinkroman API key.baseUrl
(optional): The base URL of the Thinkroman tr. Defaults tohttps://api.thinkroman.com
.retry
(optional): Retry configuration for failed requests.attempts
(optional): The maximum number of retry attempts. Defaults to 5.backoff
(optional): A function that returns the number of milliseconds to wait before the next retry attempt. Defaults to an exponential backoff.
cache
(optional): Thefetch
cache behavior. Defaults toundefined
.
Add Package
deno add jsr:@thinkroman/api
Import symbol
import * as api from "@thinkroman/api";
Import directly with a jsr specifier
import * as api from "jsr:@thinkroman/api";
Add Package
pnpm i jsr:@thinkroman/api
pnpm dlx jsr add @thinkroman/api
Import symbol
import * as api from "@thinkroman/api";
Add Package
yarn add jsr:@thinkroman/api
yarn dlx jsr add @thinkroman/api
Import symbol
import * as api from "@thinkroman/api";
Add Package
npx jsr add @thinkroman/api
Import symbol
import * as api from "@thinkroman/api";
Add Package
bunx jsr add @thinkroman/api
Import symbol
import * as api from "@thinkroman/api";