L
L
Lynatik0012020-06-20 23:02:44
JavaScript
Lynatik001, 2020-06-20 23:02:44

How to collect the entire signature of the bot, and send them a private message (from the bot)?

I use the Telegraf library - and I can’t even find something in the documentation how to send a private message.
Yes, and a command that would return the list of subscribers. also haven't found it yet.

And what is the best way to implement it?
To push in a DB to which already sent? - if for example the audience of the bot is 3k people. - then it can also be interrupted, not re-send the same?

Or is there an easier way? :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lynatik001, 2020-06-21
@Lynatik001

bot.telegram.sendMessage(iduser, `Hi`);
That's just how to find out all users now. that ever communicated with the bot.
if there is no such list of subscribers - or what I don’t remember there, was there a button to subscribe before starting communication with the bot

D
DTPlayer, 2020-06-20
@DTPlayer

# -*- coding: utf-8 -*-
import sett
import telebot
import random
import menu
from telebot import types
import time
import traceback

bot = telebot.TeleBot(sett.token)

joinedFile = open('/root/users.txt', 'r')
joinedUser = set()
for line in joinedFile:
    joinedUser.add(line.strip())
joinedFile.close()

@bot.message_handler(commands=['start'])
def start(message):
  try:
    if not str(message.chat.id) in joinedUser:
      file = open('/root/users.txt', 'a')
      file.write(str(message.chat.id) + '\n')
      file.close()
  except Exception as e:
    print(e)
    bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')

@bot.message_handler(commands=['spam'])
def spam(message):
    try:
        if message.chat.id == sett.admin_id:
            for user in joinedUser:
                bot.send_message(user, message.text[message.text.find(' '):])
    except Exception as e:
        print(e)
        bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')

@bot.message_handler(commands=['stats'])
def stats(message):
    try:
        if message.chat.id == sett.admin_id:
            joinedFile = open('/root/users.txt', 'r')
            bot.send_message(message.chat.id, 'Пользователей: *'+str(len(joinedFile.readlines()))'*, parse_mode='markdown')
            joinedFile.close
    except Exception as e:
        print(e)
        bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')

/start - if there is no id, write it down
/spam - send messages to everyone
/stats - number of users in the bot
The code is in python, but it does not really differ from js

A
Anton, 2020-06-20
Semenov

In English, but suddenly https://dev.to/rizkyrajitha/get-notifications-with...
https://core.telegram.org/bots/api#sendmessage
But it seems to me that nothing can be sent to anyone until the user himself initiated a bot

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question