MCPcopy Index your code
hub / github.com/TiagoDanin/Telegraf-Test

github.com/TiagoDanin/Telegraf-Test @v1.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.0 ↗ · + Follow
28 symbols 71 edges 2 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Telegraf Test Codacy Badge Build Status Known Vulnerabilities

Telegraf Test - Simple Test ToolKit of Telegram Bots

Features

  • Telegram bot api server emulator.
  • Compatible with Telegraf <3.
  • Compatible with test framework.
  • Send message, inline query and callback query.
  • Work in local network.

Installation

This is a Node.js module available through the npm registry. It can be installed using the npm command line tools.

npm install telegraf-test --save

How to Use

Example

const Telegraf = require('telegraf')
const TelegrafTest = require('telegraf-test')

const port = 3000
const secretPath = 'secret-path'

const bot = new Telegraf('ABCD:1234567890')
const test = new TelegrafTest({
    url: `http://127.0.0.1:${port}/${secretPath}`
})

test.setUser({
    id: 1234,
    username: '@Jack'
    //...//
}) /*return {
    id: 1234,
    is_bot: false,
    first_name: 'FIST-NAME',
    last_name: '',
    username: '@Jack',
    language_code: 'en-US'
}*/

bot.hears(/ping/i, (ctx) => {
    ctx.reply('Pong!')
})

bot.startWebhook(`/${secretPath}`, null, port)

test.sendMessageWithText('/ping')
    .then((res) => {
        console.log(res.data)
        //return { method: 'sendMessage', chat_id: 1234567890, text: 'Pong!' }
    })
    .catch((err) => {
        console.error(err)
    })

Options of Class TelegrafTest({options})

  • url - String

    Webhook url of your bot.

Default value: http://127.0.0.1:3000/secret-path - axios - Object Config/option of Axios.

Default value: {headers: {'content-type': 'application/json'}, method: 'POST'} - port - Number Server emulator port.

Default value: 2000 - token - String Bot token.

Default value: ABCD:1234567890

API

Set & Get Objects

Default value: Start in 0 - setWebhook({params}) - setAllowedUpdates({params})

Get Objects

  • getUser()
  • getChat()
  • getMessage()
  • getInlineQuery()
  • getCallbackQuery()
  • getUpdateId()
  • getWebhook()
  • getAllowedUpdates()

Send Requests

Return request of axios or false in updates ignored.

  • sendUpdate({params})
  • sendMessage({params})
  • sendMessageWithText(text: String, {params})
  • sendInlineQuery(query: String, {params})
  • sendCallbackQuery({params})
  • sendCallbackQueryWithData(data: String, {params})

[WIP] Web Server

Telegram Bot Api Server Emulator. Start with startServer().

Using with a Test Framework

You create a test suite with Mocha and ExpectJS.

Example test.js:

const expect = require('expect.js')
describe('bot', function() {
    it('/ping', async function() {
        var r = await test.sendMessageWithText('/ping')
        expect(r.data.text).to.be.a('string')
        expect(r.data.text).to.contain('Pong!')
    })
})

Run with $ mocha --exit --timeout 100000

Using Debug

Set environment variables DEBUG=telgraf:test.

Dependencies

  • axios: Promise based HTTP client for the browser and node.js
  • debug: small debugging utility
  • express: Fast, unopinionated, minimalist web framework

Dev Dependencies

  • telegraf: 📡 Modern Telegram bot framework
  • mocha: simple, flexible, fun test framework

License

MIT

Core symbols most depended-on inside this repo

Shape

Method 26
Class 2

Languages

TypeScript100%

Modules by API surface

index.js28 symbols

For agents

$ claude mcp add Telegraf-Test \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page