Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send Message without Event #58

Closed
L-U-C-K-Y opened this issue May 2, 2017 · 4 comments
Closed

Send Message without Event #58

L-U-C-K-Y opened this issue May 2, 2017 · 4 comments

Comments

@L-U-C-K-Y
Copy link

Hi mullwar

Many thanks for your awesome API!

I'm trying to use your API to send simple notifications without an event and I'm using following code:
bot.sendMessage(<user-id>, "message");

But I get following error:
(node:5735) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]

I've created the bot object as following:
const TeleBot = require('telebot'); const bot = new TeleBot({ token: '<token>, // Required. Telegram Bot API token. webhook: { // Optional. Use webhook instead of polling. key: './cert/key.pem', // Optional. Private key for server. cert: './cert/cert.pem', // Optional. Public key. url: 'https://127.0.0.1', // HTTPS url to send updates to. host: '127.0.0.1', // Webhook server host. port: 88 // Server port. } });

I'm listening via an express server.

Could you help me out?

Thank you very much!!

@mullwar
Copy link
Owner

mullwar commented May 3, 2017

Hi,

Hm, this should work fine. Try this code:

const TeleBot = require('telebot');

const TOKEN = 'TELEGRAM_BOT_TOKEN';
const USER = 000000;

const bot = new TeleBot(TOKEN);

bot.sendMessage(USER, "Hello!");

To get idea whats going on, let's print server response to console log:

bot.sendMessage(USER, "Testing!").then((response) => {
    console.log('Ok:', response);
}).catch((error) => {
    console.log('Error:', error);
});

@L-U-C-K-Y
Copy link
Author

Hi mullwar

Thanks for your fast response, I actually got it working with your code when the full error showed up!

Fix: I had to first start the bot in Telegram itself...

Thank you!

@mullwar
Copy link
Owner

mullwar commented May 3, 2017

Nice! If you have any questions, don't hesitate to ask. Also, you can join to our Telegram community group: https://goo.gl/gXvm12

@mullwar mullwar closed this as completed May 3, 2017
@h22k
Copy link

h22k commented May 8, 2022

Hi,

Hm, this should work fine. Try this code:

const TeleBot = require('telebot');

const TOKEN = 'TELEGRAM_BOT_TOKEN';
const USER = 000000;

const bot = new TeleBot(TOKEN);

bot.sendMessage(USER, "Hello!");

To get idea whats going on, let's print server response to console log:

bot.sendMessage(USER, "Testing!").then((response) => {
    console.log('Ok:', response);
}).catch((error) => {
    console.log('Error:', error);
});

it worked for me. thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants