Telegram Bot SDK

Telegram Bot SDK

Receive decision requests in your Telegram bot

Download

Installation


  npm install @noxy-network/telegram-bot-sdk@2.1.0
  # or
  yarn add @noxy-network/telegram-bot-sdk@2.1.0
  # or
  pnpm add @noxy-network/telegram-bot-sdk@2.1.0
  
Code

Quick Start


  import { NoxyTelegramClient, NoxyDecisionOutcomeValues, NOXY_IDENTITY_TYPE } from '@noxy-network/telegram-bot-sdk';

  const client = await NoxyTelegramClient.create({
    // identity types: wallet, email, phone, user_id
    identity: {
      identityType: NOXY_IDENTITY_TYPE.USER_ID,
      identityId: 'telegram-user-123',
    },
    network: {
      appId: 'your-app-id',
      relayUrl: 'https://relay.noxy.network',
      appSigningSecret: 'your-app-signing-secret',
    },
    storage: { dataDir: './.noxy-data' },
  });
  
  // Initialize the client
  await client.initialize();
  
  // Subscribe to decision requests
  await client.on(async (decisionId, decision) => {
    // Update Telegram UI, wait for user tap, then:
    const isApproved = await showConfirmDialog(decision);

    // Send decision outcome to Noxy, which will be orchestrated to your agent
    await client.sendDecisionOutcome(
      decisionId,
      isApproved ? NoxyDecisionOutcomeValues.APPROVE : NoxyDecisionOutcomeValues.REJECT,
    );
  });
  
  // when finished, disconnect from Noxy
  await client.close();