Telegraf Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Features
- Telegram bot api server emulator.
- Compatible with Telegraf <3.
- Compatible with Mocha e others test framework.
- Send message, inline query and callback query.
- Work in local network.
- Offline
Installation
Module available through the npm registry. It can be installed using the npm
or yarn
command line tool.
# Yarn (Recomend) yarn add telegraf-test# NPM npm install telegraf-test --save
Example
const Telegraf = const TelegrafTest = const port = 3000const secretPath = 'secret-path' const bot = 'ABCD:1234567890'const test = url: `http://127.0.0.1:/` test /* Return { id: 1234, is_bot: false, first_name: 'FIST-NAME', last_name: '', username: '@TiagoEDGE', language_code: 'en-US'} */ bot bot test
Documentation
TelegrafTest({options})
Options of Class - 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
- setBot({params})
- setUser({params})
- setChat({params})
- setMessage({params})
- setInlineQuery({params})
- setCallbackQuery({params})
- setUpdateId(id: Number)
Update id.
Default value: Start in0
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()
.
- startServer() - Return Express App Object
Support methods:
Using with a Test Framework
You create a test suite with Mocha and ExpectJS.
Example test.js
:
const expect =
Run with $ mocha --exit --timeout 100000
Using Debug
Set environment variables DEBUG=telgraf:test
.
Tests
To run the test suite, first install the dependencies, then run test
:
# Using Yarn yarn test# Using NPM npm run test
Dependencies
axios: Promise based HTTP client for the browser and node.js
Author: Matt ZabriskieLicense: MIT
Version: ^0.19.2
express: Fast, unopinionated, minimalist web framework
Author: TJ HolowaychukLicense: MIT
Version: ^4.17.1
Dev Dependencies
Contributors
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. List of all contributors.