Skip to content

Latest commit

 

History

History
146 lines (124 loc) · 6.91 KB

documentation.md

File metadata and controls

146 lines (124 loc) · 6.91 KB

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

Update id.
Default value: Start in 0

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 = 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.