How to add multiple users in telegram channel using ImportChatInviteRequest in python - telethon

I'm having trouble adding multiple users to the telegram channel by using the invite link ImportChatInviteRequest in python.
I have tried the telethon documentation about ImportChatInviteRequest but it only adds me to the channel and since I'm already a member of the channel and the Admin I don't want to add myself.
from telethon.tl.functions.messages import ImportChatInviteRequest
updates = await client(ImportChatInviteRequest('AAAAAEHbEkejzxUjAUCfYg'))
I have tried the above code but like I said it only add me and I am the admin. Whenever I run this program this error shows up
Error: The authenticated user is already a participant of the chat (caused by ImportChatInviteRequest)
what I want to know is that is it possible to add multiple users using ImportChatInviteRequest and can you show it to me?

Related

How does telethon judge whether the chat is a group or a user? for bot

What I need is the type of this chat message, whether it is a personal conversation or a group conversation, not the interlocutor (I don't know if I say this, can you understand what I mean
https://docs.telethon.dev/en/stable/modules/custom.html?highlight=group#module-telethon.tl.custom.dialog
async for dialog in client.iter_dialogs():
if dialog.is_channel:
....
I looked through the documentation to find this, and after using it, it shows "telethon.errors.rpcerrorlist.BotMethodInvalidError: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by GetDialogsRequest)
"
#lonami,
Is there any other way?
iter_dialogs method is only for user clients not for bot clients and you can use
await client.get_entity(<id or username here>) which gives your info about whether the id belongs to user or a chat or a bot.

How to delete a Telegram-bot user from db, when user delete the chat of the bot

I am programming telegram-bot on Python, using aiogram and I need to delete user from database, when he delete the chat of the bot. I know that bot must receive some update, after user delete the chat of the bot. But my bot doesn't receive nothing messages about it. I tried sending a message to the user who deleted the bot hoping to get an error and then process it and remove the user from the database but the messages are still sent without error. Also I read about method sendChatAction, that can solve it, but I didn't find good examples with it. Any idea? P.S. I don't need advice how to delete user from database, I want to know how to get errors with info that user deleted the chat of the bot, that I can process(exception handling)
You can use the Update.my_chat_member updates. Those will tell you when a user blocks your bot. Note that your bot does not get notified if the user simply clears the chat history or deletes the chat with your bot without blocking the bot.
Maybe it will help someone. I use Flask-SQLAlchemy for working with database and aiogram for bot-development. Make sure that you import this "from aiogram.utils.exceptions import BotBlocked" for handling exception about blocking bot by user.
from bot_files.models import db, Users
from aiogram.utils.exceptions import BotBlocked
async def technical_works(bot):
users = Users.query.all()
for user in users:
try:
await bot.send_chat_action(user.telegram_id, action="typing")
except BotBlocked as exception_info:
db.session.delete(user)
print("User is deleted")
db.session.commit()

How can I find telegram user by id

I'm using telegram bot and can get user id from incoming message.
Sometimes I want to find users who communicate with telegram bot and write them message by myself.
I have only user id and have not some additional information about the user.
Can I somehow find users by id or anonimity with only id available is by design?
At least what I've been using...
Program your bot to send you a message with link to that user.
This can be done by using link in your message (must be used as message entity or inline keyboard button):
tg://user?id=<user_id>
Or in case you are using MarkdownV2 for formatting
[inline mention of a user](tg://user?id=<user_id>)
Then, by clicking on that link, you will open a user profile, where you can message your target.
Note, user can change his privacy settings, and disable mentions. In this case these links will not work.

Joining a twilio channel with a user who already exists

I have a React Native app which uses the Twilio Chat API to connect to a channel. I am using this repo: https://github.com/twilio/TwilioChatJsReactNative
I am using this.generalChannel.join() to join my general channel. This works for any new user.
I have the token generator running in the background as per the documentation in the readme of the repo.
However, when I try to login with an existing user's name, I get an error with the statusText of 'Member already exists'.
How can I log in to my Twilio Chat channel with an existing user?
In the channel object there is a state object. In there is status, which will equal joined if the user is already a member of the channel. Just do something like if(channel.state.status !== "joined") channel.join().
There is a distinction between member and user. A User is a user of the entire chat app. A Member is an instance of that a user being in a channel. You're trying to join a channel that the user is already a member of. Basically you don't need to call join() there.
A user can be a member of multiple channels, but can only be a single member in a given channel.

Direct invitation or simple msg stanza doesn't get sent through openfire if connected to room using muc

We are trying to build a chat application in MVC using strophe.js.
We have created a chat room using rest api and want another user to join the room.
We tried to send a direct invitation using below code. but somehow, stanzas are not getting generated and sent. even no error is thrown.
Even, we tried to send a simple message to another user. but that also doesn't show up in network panel in firefox or reach to another user.
We have added other user to the roster and vice versa with both subscription. but somehow, none of the messages get sent.
We added mediated invitation before this stanza. it gets sent; I mean no error is received. but doesn't get received on another end.
could it be, we are using an old version of strophe.js? we are using one from professional XMPP book source code.
we actually tried very latest from GitHub. but then also there was no luck
will appreciate any help! thanks in advance
XMPPComm.connection.send($msg({
from: XMPPComm.User_Id,
to: to + '#servername'
})
.c('x', {xmlns: "jabber:x:conference",jid: RoomId
}));
var message = $msg({
to: to + 'servername',"type": "chat" })
.c('body').t('Room Joining invitation by sachin ,' + RoomId).up()
.c('active', { xmlns: "http://jabber.org/protocol/chatstates" });
somehow, our chat on existing chat room created works fine.
Regards,
pravin