Secrets
Secrets play a vital role in managing sensitive information, such as API keys and credentials, within Chatbotkit. This guide provides a comprehensive overview of how to handle secrets using the Chatbotkit SDK.
1. Secrets Overview
A Secret is a secure key-value pair stored in Chatbotkit for use by agents. Secrets can be categorized as shared or personal and can store various types of credentials.
Creating a Secret
To create a new secret in Chatbotkit, use the secret.create() method with parameters specifying the secret's description, visibility, name, type, and value.
const secret = await cbk.secret.create({ description: 'API key for payment gateway', kind: 'shared', name: 'PaymentAPIKey', type: 'bearer', value: 'sk_live_12345' });
javascript
description
: Brief info about the secret.kind
: Visibility type (shared
orpersonal
).type
: Credential type (plain
,basic
,bearer
,oauth
,template
).value
: The sensitive credential.
Fetching a Secret
The fetch() method retrieves a specific secret's details using its unique identifier, allowing secure access to the stored sensitive information.
const secret = await cbk.secret.fetch('123');
javascript
- Retrieves a secret by its ID.
Listing All Secrets
The list() method allows you to retrieve all secrets in your workspace with optional parameters for sorting and pagination control.
const secrets = await cbk.secret.list({ order: 'asc', take: 20 });
javascript
- Lists all secrets with sorting and pagination options.
Updating a Secret
The update() method allows you to modify existing secrets by providing the secret ID and updated properties such as description or value.
const updatedSecret = await cbk.secret.update('123', { description: 'Updated payment gateway key', value: 'sk_live_67890' });
javascript
- Modifies an existing secret.
Deleting a Secret
The delete() method permanently removes a secret from your workspace using its unique identifier.
const result = await cbk.secret.delete('123');
javascript
- Permanently removes a secret.
2. Secret Types and Usage
- Plain: Simple text secrets.
- Basic: Stores username-password pairs.
- Bearer: Stores API keys for authentication.
- OAuth: Stores OAuth tokens for authorization.
- Template: Reusable patterns for dynamic secrets.
Conclusion
This guide covers the essential operations for managing secrets in Chatbotkit, enabling secure storage and controlled access to sensitive information. Effective use of secrets ensures security and modularity within your chatbot agents.