Skip to main content
The official g-tateth SDK for JavaScript and TypeScript.

Installation

npm install @g-tateth/sdk
Or with yarn:
yarn add @g-tateth/sdk

Quick Start

import { createClient } from '@g-tateth/sdk';

const client = createClient({
  apiKey: 'sk_live_your_api_key_here',
  baseURL: 'https://api.g-tateth.com' // Optional, defaults to production
});

// List conversations
const conversations = await client.conversations.list();

// Get a conversation
const conversation = await client.conversations.get('conversation_id');

// List customers
const customers = await client.customers.list();

// Create a customer
const newCustomer = await client.customers.create({
  profile: {
    firstName: 'John',
    lastName: 'Doe',
    email: 'john@example.com'
  }
});

Configuration

Options

interface ClientOptions {
  apiKey: string;
  baseURL?: string; // Default: 'https://api.g-tateth.com'
  timeout?: number; // Default: 30000ms
  retries?: number; // Default: 3
}

Environment Variables

You can also configure the client using environment variables:
G_TATETH_API_KEY=sk_live_your_api_key
G_TATETH_BASE_URL=https://api.g-tateth.com
const client = createClient(); // Uses environment variables

API Methods

Conversations

// List conversations
const conversations = await client.conversations.list({
  status: 'open',
  page: 1,
  limit: 50
});

// Get conversation
const conversation = await client.conversations.get('conversation_id');

// Create conversation
const newConversation = await client.conversations.create({
  subject: 'Customer inquiry',
  customerId: 'customer_id',
  channel: 'email'
});

// Update conversation
await client.conversations.update('conversation_id', {
  status: 'closed'
});

// Delete conversation
await client.conversations.delete('conversation_id');

Customers

// List customers
const customers = await client.customers.list({
  search: 'john',
  page: 1,
  limit: 50
});

// Get customer
const customer = await client.customers.get('customer_id');

// Create customer
const newCustomer = await client.customers.create({
  profile: {
    firstName: 'John',
    lastName: 'Doe',
    email: 'john@example.com'
  }
});

// Update customer
await client.customers.update('customer_id', {
  profile: {
    company: 'Acme Corp'
  }
});

// Delete customer
await client.customers.delete('customer_id');

Webhooks

// List webhooks
const webhooks = await client.webhooks.list();

// Create webhook
const webhook = await client.webhooks.create({
  name: 'My Webhook',
  url: 'https://myapp.com/webhooks',
  events: ['conversation.created', 'customer.updated']
});

// Get webhook
const webhook = await client.webhooks.get('webhook_id');

// Update webhook
await client.webhooks.update('webhook_id', {
  isActive: false
});

// Delete webhook
await client.webhooks.delete('webhook_id');

Analytics

// Get usage statistics
const usage = await client.analytics.getUsage({
  startDate: '2024-01-01',
  endDate: '2024-01-31'
});

// Get performance metrics
const metrics = await client.analytics.getMetrics({
  days: 7
});

Error Handling

The SDK throws custom error types:
import { GtatethError, RateLimitError, AuthenticationError } from '@g-tateth/sdk';

try {
  await client.conversations.list();
} catch (error) {
  if (error instanceof RateLimitError) {
    console.log('Rate limit exceeded:', error.retryAfter);
  } else if (error instanceof AuthenticationError) {
    console.log('Authentication failed:', error.message);
  } else if (error instanceof GtatethError) {
    console.log('API error:', error.code, error.message);
  }
}

Retry Logic

The SDK automatically retries failed requests with exponential backoff:
const client = createClient({
  apiKey: 'sk_live_your_api_key',
  retries: 3 // Number of retry attempts
});

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:
import { Conversation, Customer, Webhook } from '@g-tateth/sdk';

const conversation: Conversation = await client.conversations.get('id');

Examples

Pagination

async function getAllConversations() {
  let page = 1;
  let allConversations = [];
  
  while (true) {
    const response = await client.conversations.list({ page, limit: 50 });
    allConversations.push(...response.data);
    
    if (page >= response.pagination.totalPages) break;
    page++;
  }
  
  return allConversations;
}

Error Handling

async function safeGetConversation(id: string) {
  try {
    return await client.conversations.get(id);
  } catch (error) {
    if (error instanceof GtatethError) {
      console.error(`API Error: ${error.code} - ${error.message}`);
    }
    throw error;
  }
}

Resources