mast / telegram-bot-api

First Telegram Bot API node.js library
http://mast.github.io/telegram-bot-api/
MIT License
245 stars 65 forks source link

setting reply_markup throws error in sendMessage method #75

Closed RatakondalaArun closed 4 years ago

RatakondalaArun commented 4 years ago

Description

Adding reply_markup key to sendMessage method's object argument throws an error.

Am I doing wrong or is it a bug?

Package version

telegram-bot-api: ^1.3.4

Thanks in advance.

Code

import telegramBot = require('telegram-bot-api');

botApi = new telegramBot({
        token: process.env['BOT_TOKEN'],
});

await this.botApi.sendMessage({
                chat_id: user.chatId,
                text: message.toTemplate(),
                parse_mode: 'Markdown',
                reply_markup: { //<-- adding this key causes error
                    inline_keyboard: [
                        [
                            {
                                text: 'test',
                                callback_data: 'testCallback',
                            },
                        ],
                    ],
                },
            });

Stacktrace

TypeError: source.on is not a function
    at Function.DelayedStream.create (E:\Projects\github-watchman\node_modules\delayed-stream\lib\delayed_stream.js:33:10)
    at FormData.CombinedStream.append (E:\Projects\github-watchman\node_modules\combined-stream\lib\combined_stream.js:45:37)
    at FormData.append (E:\Projects\github-watchman\node_modules\form-data\lib\form_data.js:74:3)
    at appendFormValue (E:\Projects\github-watchman\node_modules\request\request.js:326:21)
    at Request.init (E:\Projects\github-watchman\node_modules\request\request.js:337:11)
    at Request.RP$initInterceptor [as init] (E:\Projects\github-watchman\node_modules\request-promise-core\configure\request2.js:45:29)
    at new Request (E:\Projects\github-watchman\node_modules\request\request.js:127:8)
    at request (E:\Projects\github-watchman\node_modules\request\index.js:53:10)
    at E:\Projects\github-watchman\node_modules\request\index.js:100:12
    at E:\Projects\github-watchman\node_modules\telegram-bot-api\lib\telegram-bot.js:253:13
    at Promise._execute (E:\Projects\github-watchman\node_modules\bluebird\js\release\debuggability.js:384:9)
    at Promise._resolveFromExecutor (E:\Projects\github-watchman\node_modules\bluebird\js\release\promise.js:518:18)
    at new Promise (E:\Projects\github-watchman\node_modules\bluebird\js\release\promise.js:103:10)
    at TelegramApi.sendMessage (E:\Projects\github-watchman\node_modules\telegram-bot-api\lib\telegram-bot.js:251:16)
    at TelegramBot.<anonymous> (E:\Projects\github-watchman\src\bot\telegram\telegram_bot.ts:36:31)
    at Generator.next (<anonymous>)
    at E:\Projects\github-watchman\src\bot\telegram\telegram_bot.ts:27:71
    at new Promise (<anonymous>)
    at __awaiter (E:\Projects\github-watchman\src\bot\telegram\telegram_bot.ts:23:12)
    at TelegramBot.sendMessage (E:\Projects\github-watchman\src\bot\telegram\telegram_bot.ts:67:16)
    at E:\Projects\github-watchman\src\telegram_api\telegrammessage_mapper.ts:20:23
    at Generator.next (<anonymous>)

@mast

mast commented 4 years ago

Library is not designed to work with ts. It might be an issue with your integration. But also, since you are using 1.3.4, you have to JSON.stringify object you pass to reply_markup. If you are using 2.0.0 and higher, you don't have to do that.

RatakondalaArun commented 4 years ago

Thanks But JSON.stringify didn't work for me.