npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

telegram-nodity

v0.1.1

Published

A clean and robust Node.js module to interact with official Telegram Bot API

Downloads

29

Readme

Telegram Bot API for Node.js

A clean and robust Node.js module to interact with official Telegram Bot API.

Install

npm install --save telegram-nodity
const telegram_nodity = require('telegram-nodity')

const tg = new telegram_nodity({
	method : 'update', // update => run in getUpdates, hook => run in webhook
	api : {
		token : "BOT_TOKEN",
		id : "BOT_NAME"
	},
	response : {
		parse_mode : "Markdown"
	},
})

tg.on('message', (request, response) =>
{
	response.reply(request.getText(), (_err, _res) =>
		response.end()
	)
})

telegram_nodity(options)

method

string

hook: run in 127.0.0.2:3313 and listen for webhook request (default)

update: run a task and check getUpdates every 1000ms

server

object

host

string

if method is hook server run in this host (default is 127.0.0.2)

port

nubmer

if method is hook server run in this port (default is 3313)

update_listen_timeout

number

if method is update this property is request.timeout for getUpdates (default is 2000ms)

update_listen_time

number

if method is update this property is send request every update_listen_time in getUpdates (default is 1000ms)

queue_timeout

number

if don't use response.end() in every reques, end request after queue_timeout (default is 3000ms)

events

telegram send nine event to bot (message, edited_message, channel_post, edited_channel_post, inline_query, chosen_inline_result, callback_query, shipping_query, pre_checkout_query); telegram-nodity send every event to custom router

tg.on('message', (request, response) => {})
tg.on('edited_message', (request, response) => {})
tg.on('channel_post', (request, response) => {})
tg.on('edited_channel_post', (request, response) => {})
tg.on('inline_query', (request, response) => {})
tg.on('chosen_inline_result', (request, response) => {})
tg.on('callback_query', (request, response) => {})
tg.on('shipping_query', (request, response) => {})
tg.on('pre_checkout_query', (request, response) => {})

tg.on('text', (request, response) => {})
tg.on('type:photo', (request, response) => {})
tg.on('file', (request, response) => {})
tg.on('forward', (request, response) => {})
tg.on('reply', (request, response) => {})

message, edited_message, channel_post, edited_channel_post(request, response)

request
getText()

return message.text or message.caption

tg.on('message', (request, response) => {
	console.log(request.getText())
    response.end()
})
getMessage_id()

return message message_id

tg.on('message', (request, response) => {
	console.log(request.getMessage_id())
    response.end()
})
getChat_id()

return message message.chat.id

tg.on('message', (request, response) => {
	console.log(request.getChat_id())
    response.end()
})
getUser_id()

return message user.id

tg.on('message', (request, response) => {
	console.log(request.getUser_id())
    response.end()
})
getEdit_date()

return message.edit_date

getForward(_demand)

return message get forward properties

getForward_user_id()

return message message.forward_from.id

getForward_user()

return message message.forward_from

getForward_chat_id()

return message message.forward_from_chat.id

getForward_chat()

return message message.forward_from_chat

getForward_message_id()

return message message.forward_from_message_id

getForward_date()

return message message.forward_date

getReply_message_id()

return message message.reply_to_message.message_id

type

return text | photo | audio | voice | video | document | photo | sticker | contact | venue

ID

return message.from.id

isText

return true if type is text

text

return

isFile

return true if type is send file

isAction

return true if send group or channel action

action

return action type if isAction is true

isSticker

return true if type is sticker

isContact

return true if type is contact

isVenue

return true if type is venue

... and other methods and properties

response
end()

end this request, if don't use this, request ended after tg.queue_timeout

send(_method, _parameters, _callback = null)

send _method with _parameters to telegram and call _callback(err, response) after end request

reply(_parameters, _callback = null)

reply to request.message.message_id with _parameters and call _callback(err, response) after end request

tg.on('message', (request, response) => {
	response.reply('Hello', (err, resp) => {
    	response.end()
    })
})
tg.on('message', (request, response) => {
	response.reply({text: 'hello'}, (err, resp) => {
    	response.end()
    })
})
message(_parameters, _callback = null)

sendMessage to message.chat.id with _parameters and call _callback(err, response) after end request

pv(_parameters, _callback = null)

sendMessage to message.user.id with _parameters and call _callback(err, response) after end request

forward_from(_parameters, _callback = null)

forward message from _parameters to message.user.id and call _callback(err, response) after end request

forward_to(_parameters, _callback = null)

forward message.message_id to _parameters and call _callback(err, response) after end request

callback_query(request, response)

request
getUser_id ()
getCallback_id ()
getData ()
getChat_instance ()
getInline_message_id ()
response

message response + =>

answer()

inline_query(request, response)

request
getInline_id ()
getLocation ()
getQuery ()
getOffset ()
response

message response + =>

answer()

chosen_inline_result(request, response)

request
getResult_id ()
getLocation ()
getQuery ()
response

message response + =>