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

extension-telegram-node-bot

v1.1.4

Published

extension-telegram-node-bot base on telegram-node-bot

Downloads

23

Readme

Live Demo - YouPin Bot

YouTube extension-telegram-node-bot extension-telegram-node-bot

Extension for Telegram Node Bot

base on telegram-node-bot

Feature

  • Powerful Form Button: back, cancel, confirm Select multiple script for form Confirm (yes/no) for form Example: you ask user, would you like write comment? if user choose yes - add comment form else skip
  • New InlineMenu Single InlineMenu Many InlineMenu

Installation

To install the stable version:

npm install --save extension-telegram-node-bot

This assumes you are using npm as your package manager. If you don’t, you can access these files on unpkg, download them, or point your package manager to them.

Get started

const BotExtension = require('extension-telegram-node-bot')

Request telegram-node-bot in global variable

global.Telegram = require('telegram-node-bot')

Add extension

tg.addScopeExtension(BotExtension.runCustomForm)
tg.addScopeExtension(BotExtension.runCustomInlineMenu)

runCustomForm

Form Config

const config = {
    title: 'Order Pizza', // Title Form
    confirm: {
        text: 'confirm', // button
            message: (result) => {
            return `You name is ${result.name}`
                +`\nPizza is ${result.pizza}`
                +`\nSize is ${result.size}`
                +`\nLocation \u2714`
                +`\nComment${result.addcomment ? `: ${result.comment}` : ' \u2717'}`
        },
        resize_keyboard: true
    },
    back: {
        text: 'Back' // button
    },
    cancel: {
        text: 'Cancel', // button
            message: 'You canceled order pizza',
            callback: ($) => {
            console.log('cancel')
        }
    }
}

Form base item

name: {
    text: 'You name', // Question
        question: true, // If you need symbol "?" set true
        error: 'Sorry, you name is incorrect',
        extramess: 'Only 3 symbel', // Extra message
        keyboard: [
        [$.message.from.firstName]
    ],
        validator: (message, callback) => {
        if(message.text)
            return callback(true, message.text)
        else callback(false)
    },
        keyboardonly: false // If you want only keybord value, set true
}

Form select item

pizza: {
    text: 'Type Pizza',
        question: true,
        error: 'Please select type pizza',
        keyboard: [
        ['Chicken BBQ', 'Chicken Club'],
        ['The Meats','Supreme']
    ],
        keyboardonly: true,
        select: true,
        selectCallback: {
        object: (button) => {
            var object
            if(button == 'Chicken BBQ')
                object = 'pizza1'
            if(button == 'Chicken Club')
                object = 'pizza2'
            if(button == 'The Meats')
                object = 'pizza3'
            if(button == 'Supreme')
                object = 'pizza4'
            return object
        },
            pizza1: {
            size: {
                text: 'Size Chicken BBQ',
                    question: true,
                    error: 'Please select Size Chicken BBQ',
                    keyboard: [
                    ['small', 'medium'],
                    ['large']
                ],
                    keyboardonly: true
            }
        },
        pizza2: {
            size: {
                text: 'Size Chicken Club',
                    question: true,
                    error: 'Please select Size Chicken Club',
                    keyboard: [
                    ['small', 'medium'],
                    ['large']
                ],
                    keyboardonly: true
            }
        },
        pizza3: {
            size: {
                text: 'Size The Meats',
                    question: true,
                    error: 'Please select Size The Meats',
                    keyboard: [
                    ['small', 'medium'],
                    ['large']
                ],
                    keyboardonly: true
            }
        },
        pizza4: {
            size: {
                text: 'Size Supreme',
                    question: true,
                    error: 'Please select Size Supreme',
                    keyboard: [
                    ['small', 'medium'],
                    ['large']
                ],
                    keyboardonly: true
            }
        }


    }
}

Form confirm item

addcomment: {
    text: 'You want write comment',
        question: true,
        error: 'Please select yes or no',
        keyboard: [
        ['Yes', 'No']
    ],
        keyboardonly: true,
        confirm: true,
        confirmCallback: {
        status: (button) => {
            if (button === "Yes")
                return true
            else
                return false
        },
            ok: {
            comment: {
                text: 'Write comment',
                    question: false,
                    error: 'Please try again, you can send only text',
                    validator: (message, callback) => {
                    if (message.text) {
                        callback(true, message.text)
                        return
                    }
                    callback(false)
                }
            }
        }
    }
}

Full code

$.runCustomForm({
    config: {
        title: 'Order Pizza', // Title Form
        confirm: {
            text: 'confirm',
            message: (result) => {
                return `You name is ${result.name}`
                    +`\nPizza is ${result.pizza}`
                    +`\nSize is ${result.size}`
                    +`\nLocation \u2714`
                    +`\nComment${result.addcomment ? `: ${result.comment}` : ' \u2717'}`
            },
            resize_keyboard: true
        },
        back: {
            text: 'Back'
        },
        cancel: {
            text: 'Cancel',
            message: 'You canceled order pizza',
            callback: ($) => {
                console.log('cancel')
            }
        }
    },
    form: { // Body form
        name: {
            text: 'You name', // Question
            question: true, // If you need symbol "?" set true
            error: 'Sorry, you name is incorrect',
            keyboard: [
                [$.message.from.firstName]
            ],
            validator: (message, callback) => {
                if(message.text)
                    return callback(true, message.text)
                else callback(false)
            },
            keyboardonly: false, // If you want only keybord value, set true
            resize_keyboard: true
        },
        pizza: {
            text: 'Type Pizza',
            question: true,
            error: 'Please select type pizza',
            keyboard: [
                ['Chicken BBQ', 'Chicken Club'],
                ['The Meats','Supreme']
            ],
            keyboardonly: true,
            select: true,
            selectCallback: {
                object: (button) => {
                    var object
                    if(button == 'Chicken BBQ')
                        object = 'pizza1'
                    if(button == 'Chicken Club')
                        object = 'pizza2'
                    if(button == 'The Meats')
                        object = 'pizza3'
                    if(button == 'Supreme')
                        object = 'pizza4'
                    return object
                },
                pizza1: {
                    size: {
                        text: 'Size Chicken BBQ',
                        question: true,
                        error: 'Please select Size Chicken BBQ',
                        keyboard: [
                            ['small', 'medium'],
                            ['large']
                        ],
                        keyboardonly: true
                    }
                },
                pizza2: {
                    size: {
                        text: 'Size Chicken Club',
                        question: true,
                        error: 'Please select Size Chicken Club',
                        keyboard: [
                            ['small', 'medium'],
                            ['large']
                        ],
                        keyboardonly: true
                    }
                },
                pizza3: {
                    size: {
                        text: 'Size The Meats',
                        question: true,
                        error: 'Please select Size The Meats',
                        keyboard: [
                            ['small', 'medium'],
                            ['large']
                        ],
                        keyboardonly: true
                    }
                },
                pizza4: {
                    size: {
                        text: 'Size Supreme',
                        question: true,
                        error: 'Please select Size Supreme',
                        keyboard: [
                            ['small', 'medium'],
                            ['large']
                        ],
                        keyboardonly: true
                    }
                }


            }
        },
        location: {
            text: 'Location for Delivery',
            question: true,
            error: 'You send incorrect location',
            validator: (message, callback) => {
                if(message.location) {
                    callback(true, message.location)
                    return
                }
                callback(false)
            }
        },
        addcomment: {
            text: 'You want write comment',
            question: true,
            error: 'Please select yes or no',
            keyboard: [
                ['Yes', 'No']
            ],
            keyboardonly: true,
            confirm: true,
            confirmCallback: {
                status: (button) => {
                    if (button === "Yes")
                        return true
                    else
                        return false
                },
                ok: {
                    comment: {
                        text: 'Write comment',
                        question: false,
                        error: 'Please try again, you can send only text',
                        validator: (message, callback) => {
                            if (message.text) {
                                callback(true, message.text)
                                return
                            }
                            callback(false)
                        }
                    }
                }
            }
        }
    }
}, (result) => {
    $.sendMessage(`${result.name}! you send form`)
})

runCustomInlineMenu

Single Menu

$.runCustomInlineMenu({
    title: 'My Cars',
    items: {
        message: 'BMW x6',
        menu: [
            [
                {
                    text: 'Sell',
                    callback: (callbackQuery, message) => {
                        console.log('Sell')
                    }
                },
                {
                    text: 'Buy',
                    callback: (callbackQuery, message) => {
                        console.log('Buy')
                    }
                }
            ],
            [
                {
                    text: 'Contact',
                    callback: (callbackQuery, message) => {
                        console.log('Contact')
                    }
                }
            ]
        ]
    }
})

Many menu

$.runCustomInlineMenu({
    title: 'My Cars',
    items: [{
        message: 'BMW x6',
        menu: [
            [
                {
                    text: 'Sell',
                    callback: (callbackQuery, message) => {
                        console.log('Sell')
                    }
                },
                {
                    text: 'Buy',
                    callback: (callbackQuery, message) => {
                        console.log('Buy')
                    }
                }
            ],
            [
                {
                    text: 'Contact',
                    callback: (callbackQuery, message) => {
                        console.log('Contact')
                    }
                }
            ]
        ]
    },
        {
            message: 'Mazda 6',
            menu: [
                [
                    {
                        text: 'Sell',
                        callback: (callbackQuery, message) => {
                            console.log('Sell')
                        }
                    },
                    {
                        text: 'Buy',
                        callback: (callbackQuery, message) => {
                            console.log('Buy')
                        }
                    }
                ],
                [
                    {
                        text: 'Contact',
                        callback: (callbackQuery, message) => {
                            console.log('Contact')
                        }
                    }
                ]
            ]
        },
        {
            message: 'Audi a6',
            menu: [
                [
                    {
                        text: 'Sell',
                        callback: (callbackQuery, message) => {
                            console.log('Sell')
                        }
                    },
                    {
                        text: 'Buy',
                        callback: (callbackQuery, message) => {
                            console.log('Buy')
                        }
                    }
                ],
                [
                    {
                        text: 'Contact',
                        callback: (callbackQuery, message) => {
                            console.log('Contact')
                        }
                    }
                ]
            ]
        }
    ]
})

Fonov Sergei 2016