0.2.1 • Published 4 years ago

vv-telegram v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Install & Use

npm i vv-telegram
const os = require('os')
const vvt = require('vv-telegram')
let bot = vvt.create('YOUR_TOKEN_BOT', {cache: {hours_life: 3}})

let t1 = 'short_text'
let t2 = 'long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text_long_text'

bot.start(error => {
    if (error) {
        console.log(error)
        process.exit()
    }
    console.log('BOT STARTED')

    bot.on_error(error => {
        console.log('ERROR IN BOT WORK:')
        console.log(error)
    })
    bot.on_message(message => {
        console.log(''.concat('message.message_id:', os.EOL, message.message_id, os.EOL, 'message.type_text:', os.EOL, message.type_text, os.EOL, 'message.text:', os.EOL, message.text))

        //demo delete prev message when user click on button in prev message
        let prev_file_find = false
        let prev_message = bot.get_from_cache_receiving({account: message.account, chat_id: message.chat_id, message_id: message.message_id, type_text: 'callback_data'})
        prev_message.forEach(m => {
            bot.message_delete(message.chat_id, m.message_id)
            prev_file_find = true
        })


        /** @type {vvt.package_sending_button[][]}  */
        let buttons = [
            [
                {text: 'b1', callback_data: '1_'.concat(t1)}, {text: 'b2', callback_data: '2_'.concat(t1)}, {text: 'b3', callback_data: '3_'.concat(t1)},
            ], [
                {text: 'b4', callback_data: '4_'.concat(t2)}, {text: 'b5', callback_data: '5_'.concat(t2)}, {text: 'b6', callback_data: '6_'.concat(t2)},
            ]
        ]

        let message_text = message.error ? 'ERROR: '.concat(message.error) : 'replay for '.concat(message.text)

        bot.message_send(
            message.account,
            message_text,
            {buttons: buttons, reply_to_message_id: prev_file_find ? undefined : message.message_id},
            undefined,
            (error, sending) => {
                if (error) {
                    console.log(error)
                    return
                }

                //demo edit prev message
                setTimeout(() => {
                    bot.message_send(
                        message.account,
                        'edited: '.concat(message_text),
                        {reply_to_message_id: message.message_id, buttons: buttons},
                        sending.message_id,
                        (error, sending) => {
                            if (error) {
                                console.log(error)
                                return
                            }
                        }
                    )
                }, 5000)
            }
        )
    })
})

Functions

Typedefs

create(token, options) ⇒ app

Kind: global function

ParamType
tokenstring
optionstype.options

button_line_to_matrix(button_line, width) ⇒ Array.<Array.<package_sending_button>>

Kind: global function

ParamType
button_lineArray.<package_sending_button>
widthnumber

button_line_to_matrix~result : Array.<Array.<package_sending_button>>

Kind: inner typedef of button_line_to_matrix

button_line_to_matrix~line : Array.<package_sending_button>

Kind: inner typedef of button_line_to_matrix

bot : app

Kind: global typedef

package_sending_button : type.package_sending_button

Kind: global typedef

package_sending_menu : type.package_sending_menu

Kind: global typedef

package_sending_options : type.package_sending_options

Kind: global typedef

package_sending_text_format : type.package_sending_text_format

Kind: global typedef

package_receiving : type.package_receiving

Kind: global typedef

package_sending : type.package_sending

Kind: global typedef

package_sending_queue : type.package_sending_queue

Kind: global typedef

file_info : type.file_info

Kind: global typedef

0.2.1

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago