How to search messages by a hashtag (like #something) using the telethon libray? - telethon

Just searching messages using get_messages() does not work:
client.get_messages(enity, search="#myhashtag")
Doesn't work. i.e. does not find messages like "A message with #myhashtag". How to search for messages by a hashtag ?

Related

Youtube LiveChat API: messageTextInvalid

I'm using the Youtube livechat.insert API (https://developers.google.com/youtube/v3/live/docs/liveChatMessages/insert), and occasionally get back the messageTextInvalid error. However the error description page doesn't give much of a hint as to what's wrong here (https://developers.google.com/youtube/v3/live/docs/errors#liveChatMessages_youtube.liveChatMessages.insert). I've ensured the messages being sent are <= 200 characters long, and do not have newlines in them. However a message like '(Discord) person: COMMENT : Wonderful!' returns this error that the text is invalid. Is there some information that I can find about what text is valid in the message? I also didn't find much information on the livechat message resource page (https://developers.google.com/youtube/v3/live/docs/liveChatMessages#resource)

Why the telegram bot doesn`t recognize the url while the hashtag '#' is at the first of the message?

I have a telegram bot by PHP which removes messages which contain url, but when the the user send the hashtag # at the first of the message it doesn't remove the url !
$input=file_get_contents("php://input");
$update=json_decode($input,true);
$entity_type=$update['message']['entities'][0]['type'];
$chat_id=$update['message']['chat']['id'];
$message_id=$update['message']['message_id'];
if ($entity_type=='url' ){
bot("deleteMessage?chat_id=".$chat_id."&message_id=".$msg_id);
}
forexample it removes www.google.com but doesn't remove
#info
www.google.com
Why it doesn't recognize the url ? Is there any clue ?
A message containing "#info www.google.com" has two entities.
You need to check if any of them is of type url.
Your code is checking only the first entity. (Which is of type hashtag and not url).

Redis PSUBSCRIBE Problems

A server is sending a message via Redis on a channel composed of some name and a unique id. I need to essentially find this channel and publish something back to it.
So far, I tried reading the documentation and experimenting with PSUBSCRIBE. However, the message that is received doesn't have the full channel name. It just has the pattern that I sent to PSUBSCRIBE. So, how can I go about finding the channel name?
I also included some code below if that would help understand my logic.
red = redis.StrictRedis(...)
pub = red.pubsub()
pub.psubscribe("name_pattern*")
for msg in pub.listen():
if msg["data"] == "...":
channel_name = msg["channel"]
red.publish(channel_name, "SOME MESSAGE")

What does Mandrill status = "invalid" mean in Send Message API response

Mandrill official documentation says that the status property in the response of Send Message API request is:
the sending status of the recipient - either "sent", "queued", "scheduled", "rejected", or "invalid"
Can't find anywhere what does invalid status indicate.
Any idea, referece ?
One reason I have found is an invalid email address. For example having two dots in a domain like this: alice#example..com
I had this happen because some of the properties in the JSON I posted had uppercase letters when the mandrill api was expecting lowercase.
I was using newtonsoft and solved it by adding JsonProperty attributes to my objects as described here: https://stackoverflow.com/a/34071205

How to forward a message in Telegram API

There are 2 methods in Telegram API that forward message:
messages.forwardMessage
messages.forwardMessages
I want to use forwardMessage method to forward a message from a channel, group or user to another one. Definition of this method is:
messages.forwardMessage#33963bf9 peer:InputPeer id:int random_id:long = Updates;
As you see this method has 3 input parameters:
peer that represents the channel, group or user that we forward message to. (Destination)
id that is message_id.
random_id that has internal use.
As we know the message_id is a unique number in a chat. so a message_id in a group has refers to a message that differs with the same message_id in other group.
So the main question is that how we determine the source peer of forwarding? Because the source peer is not determined by message_id.
P.S: My question is about methods in Telegram API, not Telegram Bot API.
There seems to an issue with ForwardMessageRequest which doesn't specify the source chat. Obviously message_id is not unique and through my tests I noticed wrong messages will be forwarded by just specifying the message_id. And I noticed message_id is not unique.
But the issue doesn't exist with ForwardMessagesRequest. Following is an example how to use the ForwardMessagesRequest version.
Forwarding Example:
Here is the code I used for testing (I am using Telethon for python, but it won't matter since it's directly calling telegram API):
source_chat = InputPeerChannel(source_chat_id, source_access_hash)
total_count, messages, senders = client.get_message_history(
source_chat, limit=10)
for msg in reversed(messages):
print ("msg:", msg.id, msg)
msg = messages[0]
print ("msg id:", msg.id)
dest_chat = InputPeerChat(dest_chat_id)
result = client.invoke(ForwardMessagesRequest(from_peer=source_chat, id=[msg.id], random_id=[generate_random_long()], to_peer=dest_chat))