-
Notifications
You must be signed in to change notification settings - Fork 82
how to send a personal message to a user? #5
Comments
I did it like this, but I'd like to see an example in the README, because I've no idea if this is how it should be done. The user_name, user_id variables come from a previous interaction. bot = TelegramBot.new(token: TELEGRAPH_KEY)
c = TelegramBot::Channel.new
c.username = user_name
c.id = user_id
o = TelegramBot::OutMessage.new
o.chat = c
o.text = "Hello"
o.send_with(bot) |
Thanks a lot, @dkam ! |
hi everyone, I am really sorry I have been super busy. The username is not needed, so you can do just this: bot = TelegramBot.new(token: TELEGRAM_KEY)
channel = TelegramBot::Channel.new(id: user_id)
o = TelegramBot::OutMessage.new
o.chat = channel
o.text = "Hello"
o.send_with(bot) Because user = TelegramBot::User.new(id: user_id)
out_message = TelegramBot::OutMessage.new
out_message.chat = user
out_message.text = "Hello"
out_message.send_with(bot) I was just going through the code and bot.get_updates do |message|
if message.group_chat?
channel_members = message.chat.users # array of User
user = channel_members.first
user.new_message do |answer|
answer.text = "Hello #{user.first_name}"
answer.send_with(bot)
end
end
end Any ideas? |
#5 Add send message instructions to README
I have a bot that will send personal message (PM) to the user who has invoked a bot command on the group. How to get this?
Thanks.
The text was updated successfully, but these errors were encountered: