I have a code that I need to join a given channel in but getting the following error
telethon.errors.rpcerrorlist.ChannelInvalidError: Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited (caused by JoinChannelRequest)
my code :
group_input = InputChannel(group.id, group.access_hash)
client(JoinChannelRequest(group_input))
here I'm using inputChannel because i looked in the joinChannelRequest and it asked for "TypeInputChannel"
and it's a union of [InputChannelEmpty,InputChannel,InputChannelFromMessage]
another things that I tried:
1-
client(JoinChannelRequest(group.id))
2-
client(JoinChannelRequest(group))
3-
group_input = InputPeerChannel(group.id, group.access_hash)
client(JoinChannelRequest(group_input))
The simplest way you can do is to retrieve the username of the public channel
Suppose the username of the channel is #The_Channel
Get the entity
entity = client.get_entity("t.me/The_Channel") #omit #
Then invoke this function
client(JoinChannelRequest(entity))
Related
I made a bot and invited it to a group.
The bot is administrator of this group, it's not private. I'm trying to make the bot send private messages to users that join the group.
The problem is that when I try to do so, I get following error:
ERROR - TeleBot: "Infinity polling exception: 'list' object has no attribute 'id'
and I cant figure out what that means, or why I get it or how to fix it.
This is my code:
import telebot
bot = telebot.TeleBot('here is bot token')
#bot.message_handler(content_types=["new_chat_members"])
def handler_new_member(message):
first_name = message.new_chat_members[0].first_name
bot.send_message(message.new_chat_members.id, "Something something".format(first_name))
bot.infinity_polling()
I tried to make the bot send private messages to new members and expected it to read the id of new members, which as far as I understand is possible.
I'm new to python and telegram api. I appreciate any help.
It seems that new_chat_members is an actual list. In the first line you're using list index to get the user's first name. Lists in Python do not have attribute id. Maybe you meant new_chat_members[index].id?
I am trying to get Users from my Telegram Group to my other Telegram Group and using this code:
group_entity = InputPeerChannel(group.id, group.access_hash)
client(InviteToChannelRequest(channel=group_entity, users=[user_to_add]))
A few weeks before this code worked perfectly fine but now I get this error:
telethon.errors.rpcerrorlist.ChannelInvalidError: Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited (caused by InviteToChannelRequest)
What am I doing wrong?
you must do like this:
group_entity = await client.get_entity(InputPeerChannel(group.id, group.access_hash))
I am a very new user to Quickfix Python. I want to send a QuoteRequest. My function to create a new quote request message is as below:
import quickfix as fix
def create_quote_request():
message = fix.Message()
header = message.getHeader()
header.setField(fix.MsgType(fix.MsgType_QuoteRequest))
gp = fix.Group()
gp.setField(fix.Symbol("GBPUSD"))
gp.setField(fix.Side(fix.Side_BUY))
gp.setField(fix.Account("TestAcc"))
gp.setField(fix.Currency("GBP"))
message.addGroup(gp)
fix.Session.sendToTarget(message, self.sessionID)
When I execute the code, I am getting error as below:
NotImplementedError: Wrong number r type of arguments for overloaded function 'new_group'.
Possible C/C++ prototypes are:
FIX::Group::Group(int, int)
FIX::Group::Group(int, int, int const[])
FIX::Group::Group(int, int, message_order const &)
FIX::Group::Group(FIX::Group const &)
I did read the documentation and found that the Group object requires arguments
Group(int field, int delim)
Not sure what to pass the values for field and delim. Appreciate your response and help.
not sure I´m on time to help. But I will try. I think #JimmyNJ is giving you proper answer.
According to official doc you can easily do it, but you don´t have to use a generic group, you have to use specific group available to your kind of message.
As far as I know, you should program something like this.
from quickfix44 import QuoteRequest
import quickfix as fix
message = QuoteRequest()
group = QuoteRequest.NoRelatedSym()
group.setField(fix.Symbol("GBPUSD"))
group.setField(fix.Side(fix.Side_BUY))
group.setField(fix.Account("TestAcc"))
group.setField(fix.Currency("GBP"))
message.addGroup(group)
I´m assuming you want to add these 4 tags into NoRelatedSym group, based in their tag numbers. I´ve also used FIX 44 version, maybe you are using a different version, but main idea is the same.
I'm using the Telethon python library for Telegram and am currently trying to add users to my group using the following: https://docs.telethon.dev/en/latest/examples/chats-and-channels.html#adding-someone-else-to-such-chat-or-channel
However, I run into a problem with the InviteToChannelRequest function whose signature is the following:
channels.inviteToChannel#199f3a6c channel:InputChannel users:Vector<InputUser> = Updates
As you can see, the channel should be of type InputChannel however when I try to create an InputChannel to pass into the function using it's constructor, which is the following:
inputChannel#afeb712e channel_id:int access_hash:long = InputChannel
I do not have the group's access_hash so I'm unable to create a InputChannel to pass into the InviteToChannelRequest function.
So how exactly do I either get the access_hash of the group I want to add users to or how do I use the InviteToChannelRequest function?
If I try to create an InputChannel without the access_hash, this is the error I get:
Thank you!
It turns out that the group I had created was set to private so I went on the telegram app and set it to public and after I did that, I ran this snippet:
result = client(GetDialogsRequest(
offset_date=last_date,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=chunk_size,
hash = 0
))
Which listed the details of the channel I wanted along with it's access_hash
I am trying to make a Slack Bot using python, and I have a issue, I am not able to get the users from a specific channel, I only succeed if I take all of the users. Basically I want only those from (eg. random channel).
Until now I tried to get the team's ID from every user and compare it to a channel ID, but that failed because everyone is having the same ID and I can't figure out why.
Here is the snippet of the code:
def users_of_the_channel():
global slack_client
#this is the variable which is initialized with SlackClient(BOT_TOKEN)
api_call = slack_client.api_call( "users.list",channel="C0XXXXXXX")
if api_call.get('ok'):
channels = api_call.get('members')
for channel in channels:
print ("this is cool : ", channel['team_id'])
The issue I believe is that when I initialize the api_call variable I call the function with the users.list argument, I tried with usergroups.list and usergroups.users.list but with no success.
Basically to keep it short I need the list with the users from a channel, and the documentation hasn't helped me.
users.list does not take channel id as input, which you are providing in your API call.
Slack provide different bot token for different teams.
Simply call api with bot token of team of which you require user list and you will get the list of members.
client = SlackClient(SLACK_BOT_TOKEN)
request = client.api_call("users.list")
if request['ok']:
for item in request['members']:
print item['name']
For more details about optional arguments you can provide with api call, refer documentation(https://api.slack.com/methods/users.list).
You probably can use the new conversations API to retrieve that (specifically conversations.members endpoint):
https://api.slack.com/methods/conversations.members