diff --git a/docs/{'title':-'node.js-sdk-documentation',-'descriptio.md b/docs/{'title':-'node.js-sdk-documentation',-'descriptio.md new file mode 100644 index 0000000..9273a41 --- /dev/null +++ b/docs/{'title':-'node.js-sdk-documentation',-'descriptio.md @@ -0,0 +1,354 @@ + +# Node.js SDK Documentation + +## Introduction + +This document provides comprehensive instructions on how to install, initialize, and use the Node.js SDK for interacting with the messaging and email services. This SDK simplifies the integration process for Node.js developers, allowing them to easily send messages via various channels (WhatsApp, Telegram, SMS, iMessage) and manage email communications. + +## Installation + +The SDK can be installed using npm or yarn: + +```bash +npm install your-sdk-name # Replace your-sdk-name with the actual package name +``` + +or + +```bash +yarn add your-sdk-name # Replace your-sdk-name with the actual package name +``` + +## Initialization + +Before using the SDK, you need to initialize it with your API key, API secret, and account ID. + +```javascript +const { YourSDK } = require('your-sdk-name'); // Replace YourSDK and your-sdk-name + +const sdk = new YourSDK({ + apiKey: 'YOUR_API_KEY', + apiSecret: 'YOUR_API_SECRET', + accountId: 'YOUR_ACCOUNT_ID', +}); +``` + +**Parameters:** + +* `apiKey` (string, required): Your API key. +* `apiSecret` (string, required): Your API secret. +* `accountId` (string, required): Your account ID. + +## Usage + +This section details how to use the SDK methods for sending messages and emails. + +### Sending Individual Messages + +The `sendMessage` method allows you to send individual messages via different services. + +```javascript +async function sendIndividualMessage() { + try { + const messageData = { + to: '61433174782', + from: '61421868490', + body: 'Hello from the Node.js SDK!', + service: 'whatsapp', // or 'telegram', 'sms', 'imessage' + }; + + const response = await sdk.sendMessage(messageData); + console.log('Message sent successfully:', response); + } catch (error) { + console.error('Error sending message:', error); + } +} + +sendIndividualMessage(); +``` + +**Parameters:** + +The `sendMessage` method accepts an object with the following properties: + +| Parameter | Type | Description | Required | +| :-------- | :----- | :---------------------------------------- | :------- | +| `to` | string | Recipient phone number. | Yes | +| `from` | string | Sender phone number. | Yes | +| `body` | string | Message body text. | Yes | +| `service` | string | Service to use (whatsapp, telegram, etc.). | Yes | + +**Response:** + +The method returns a promise that resolves with the message details upon successful sending. The response typically includes `to`, `from`, `body`, and `status`. + +**Error Handling:** + +The method throws an error if the message fails to send. Catch the error to handle failures gracefully. + +### Sending Group Messages + +The `sendGroupMessage` method allows you to send messages to a group (e.g., WhatsApp group). + +```javascript +async function sendGroupMessage() { + try { + const messageData = { + thread_id: 'GROUP_ID', // Replace with the actual group ID + body: 'Hello from the Node.js SDK to the group!', + service: 'whatsapp', // or 'telegram' + }; + + const response = await sdk.sendGroupMessage(messageData); + console.log('Group message sent successfully:', response); + } catch (error) { + console.error('Error sending group message:', error); + } +} + +sendGroupMessage(); +``` + +**Parameters:** + +The `sendGroupMessage` method accepts an object with the following properties: + +| Parameter | Type | Description | Required | +| :---------- | :----- | :---------------------------------------- | :------- | +| `thread_id` | string | The ID of the group chat. | Yes | +| `body` | string | Message body text. | Yes | +| `service` | string | Service to use (whatsapp, telegram). | Yes | + +**Response:** + +The method returns a promise that resolves with the message details upon successful sending. The response typically includes `thread_id`, `body`, and `status`. + +**Error Handling:** + +The method throws an error if the message fails to send. Catch the error to handle failures gracefully. + +### Sending Emails + +The `sendEmail` method allows you to send emails. + +```javascript +async function sendEmail() { + try { + const emailData = { + sender_address: 'jane@a101.bot', + recipient_address: 'john@a101.bot', + subject: 'Hello from Jane', + body: 'Have a nice day', + headers: { + bcc: ['jim@a101.bot', 'james@a101.bot'], + cc: ['sarah@a101.bot', 'janette@a101.bot'], + 'reply-to': 'jane@a101.bot', + }, + attachment_uri: 'https://a101.bot/attachment.pdf', + }; + + const response = await sdk.sendEmail(emailData); + console.log('Email sent successfully:', response); + } catch (error) { + console.error('Error sending email:', error); + } +} + +sendEmail(); +``` + +**Parameters:** + +The `sendEmail` method accepts an object with the following properties: + +| Parameter | Type | Description +| `accountId` | string | The ID of the account. | Yes | +| `sender_address` | string | Sender email address. | Yes | +| `recipient_address` | string | Recipient email address. | Yes | +| `subject` | string | Email subject. | Yes | +| `body` | string | Email body. | Yes | +| `headers` | object | Email headers (cc, bcc, reply-to). | No | +| `attachment_uri` | string | URI of the email attachment. | No | + +**Response:** + +The method returns a promise that resolves with the email details upon successful sending. The response typically includes `to`, `from`, `subject`, `body`, and `status`. + +**Error Handling:** + +The method throws an error if the email fails to send. Catch the error to handle failures gracefully. + +### Getting Message Details + +The `getMessageDetails` method allows you to retrieve details of a specific message. + +```javascript +async function getMessageDetails() { + try { + const messageId = 'MESSAGE_ID'; // Replace with the actual message ID + + const response = await sdk.getMessageDetails(messageId); + console.log('Message details:', response); + } catch (error) { + console.error('Error getting message details:', error); + } +} + +getMessageDetails(); +``` + +**Parameters:** + +| Parameter | Type | Description | Required | +| :---------- | :----- | :---------------------------------------- | :------- | +| `messageId` | string | The ID of the message to retrieve. | Yes | + +**Response:** + +The method returns a promise that resolves with the message details. + +**Error Handling:** + +The method throws an error if the message details cannot be retrieved. + +### Getting Recent Messages in a Thread + +The `getRecentMessages` method allows you to retrieve recent messages from a specific thread. + +```javascript +async function getRecentThreadMessages() { + try { + const threadId = 'THREAD_ID'; // Replace with the actual thread ID + + const response = await sdk.getRecentMessages(threadId); + console.log('Recent messages:', response); + } catch (error) { + console.error('Error getting recent messages:', error); + } +} + +getRecentThreadMessages(); +``` + +**Parameters:** + +| Parameter | Type | Description | Required | +| :--------- | :----- | :------------------------------------ | :------- | +| `threadId` | string | The ID of the thread to retrieve from. | Yes | + +**Response:** + +The method returns a promise that resolves with an array of recent messages. + +**Error Handling:** + +The method throws an error if the messages cannot be retrieved. + +### Getting Chat Group Details + +The `getChatGroupDetails` method allows you to retrieve details of a specific chat group. + +```javascript +async function getChatGroupDetails() { + try { + const threadId = 'THREAD_ID'; // Replace with the actual thread ID + + const response = await sdk.getChatGroupDetails(threadId); + console.log('Chat group details:', response); + } catch (error) { + console.error('Error getting chat group details:', error); + } +} + +getChatGroupDetails(); +``` + +**Parameters:** + +| Parameter | Type | Description | Required | +| :--------- | :----- | :------------------------------------ | :------- | +| `threadId` | string | The ID of the thread to retrieve. | Yes | + +**Response:** + +The method returns a promise that resolves with the chat group details. + +**Error Handling:** + +The method throws an error if the chat group details cannot be retrieved. + +### Getting All Threads + +The `getAllThreads` method allows you to retrieve all threads associated with an account. + +```javascript +async function getAllThreads() { + try { + const response = await sdk.getAllThreads(); + console.log('All threads:', response); + } catch (error) { + console.error('Error getting all threads:', error); + } +} + +getAllThreads(); +``` + +**Parameters:** + +This method does not require any parameters. + +**Response:** + +The method returns a promise that resolves with an array of all threads. + +**Error Handling:** + +The method throws an error if the threads cannot be retrieved. + +### Getting All Threads for a Phone Number + +The `getAllThreadsForPhoneNumber` method allows you to retrieve all threads associated with a specific phone number. + +```javascript +async function getAllThreadsForPhoneNumber() { + try { + const phoneNumber = '61433174782'; // Replace with the actual phone number + const response = await sdk.getAllThreadsForPhoneNumber(phoneNumber); + console.log('All threads for phone number:', response); + } catch (error) { + console.error('Error getting all threads for phone number:', error); + } +} + +getAllThreadsForPhoneNumber(); +``` + +**Parameters:** + +| Parameter | Type | Description | Required | +| :------------ | :----- | :---------------------------------------- | :------- | +| `phoneNumber` | string | The phone number to retrieve threads for. | Yes | + +**Response:** + +The method returns a promise that resolves with an array of all threads associated with the phone number. + +**Error Handling:** + +The method throws an error if the threads cannot be retrieved. + +## Best Practices + +* **Error Handling:** Always wrap your SDK calls in `try...catch` blocks to handle potential errors gracefully. +* **Asynchronous Operations:** All SDK methods are asynchronous and return promises. Use `async/await` or `.then()` to handle the results. +* **Security:** Store your API key and secret securely. Do not hardcode them directly into your application. Use environment variables or a secure configuration management system. +* **Rate Limiting:** Be mindful of rate limits imposed by the API. Implement appropriate retry mechanisms if necessary. + +## Error Codes + +(This section would list common error codes and their descriptions. This information is not available in the provided OpenAPI spec, but should be included in a real SDK documentation.) + +## Support + +For any questions or issues, please contact support at [support@example.com](mailto:support@example.com).