ESC
Start typing to search...

Create a Plugin

Build a custom plugin from scratch with this step-by-step tutorial.

Step 1: Initialize Project

Terminal
mkdir my-teleton-plugin
cd my-teleton-plugin
npm init -y
npm install @teleton/sdk typescript
npx tsc --init

Step 2: Create Manifest

manifest.json
{
  "name": "weather-plugin",
  "version": "1.0.0",
  "description": "Get weather information",
  "main": "dist/index.js",
  "tools": ["getWeather"],
  "permissions": ["network"]
}

Step 3: Implement Tool

src/index.ts
import { definePlugin, defineTool } from '@teleton/sdk';

const getWeather = defineTool({
  name: 'getWeather',
  description: 'Get current weather for a city',
  parameters: {
    type: 'object',
    properties: {
      city: {
        type: 'string',
        description: 'City name'
      }
    },
    required: ['city']
  },
  handler: async ({ city }, ctx) => {
    const apiKey = ctx.config.apiKey;
    const response = await fetch(
      `https://api.weather.com/v1?city=${city}&key=${apiKey}`
    );
    const data = await response.json();

    return {
      city,
      temperature: data.temp,
      conditions: data.conditions
    };
  }
});

export default definePlugin({
  name: 'weather-plugin',
  tools: [getWeather],
  onLoad: async (ctx) => {
    ctx.logger.info('Weather plugin loaded');
  }
});

Step 4: Build & Install

Terminal
# Build
npx tsc

# Copy to plugins directory
cp -r dist ~/.teleton/plugins/weather-plugin
config.yaml
plugins:
  - name: weather-plugin
    path: ~/.teleton/plugins/weather-plugin
    config:
      apiKey: ${WEATHER_API_KEY}

Step 5: Test

Restart Teleton and ask the agent:

Telegram
You: What's the weather in Paris?
Agent: The current weather in Paris is 18°C with partly cloudy conditions.

Best Practices

  • Use descriptive tool names and descriptions
  • Validate inputs before processing
  • Handle errors gracefully with informative messages
  • Use environment variables for sensitive config
  • Log important actions for debugging