Access previous message content from a user reply message on Telegram - c#

Does anyone know how can I access a previous message content when a user sends a reply message on Telegram?
for example:
James: hello
me: reply on James message with "hello friend"
here i want to get the hello message content or its message id in my telegram bot to process a command.
sth like this:
if(message.Contains("/delete")){
bot.DeleteMessageAsync(chatId, PreviousMessage or OriginalMessage ID)
}
PreviousMessage or OriginalMessage ID are equals to MessageId
but instead of MessageId i want to use sth like those two
I have checked telegram bot documentation and I did not find anything
How can i do it?
(Im using getUpdates method)
sorry for my poor English

You can find the original message ID in message.reply_to_message.message_id. Naming could differ depends on the library you use. More information and other attributes that could be useful you can find in the official Telegram's documentation for the Message object.

Related

Telegram Bot API C# How to get All Pinned Messages?

Telegram added the feature to pin more than one message. I'm doing it like this:
var chat = botClient.GetChatAsync(chatid).Result;
pinnedmsgtxt = chat.PinnedMessage.Text;
pinnedmsg= chat.PinnedMessage;
but I can only get the last message that was pinned. Any way to get all of them? Am I missing something? I'm using https://github.com/TelegramBots/telegram.bot
Use messages.search method with inputMessagesFilterPinned filter.
Please read more here:
Pin API
Message Search API
Pinned messages filter

Telegram Bot: get chat Id group

I've created a Telegram Bot using C# and I want to see who is using my bot when sending message.
I can get when people send a message to my bot in private chat but in the Groups, I can't get Username who is using Bot and it's return the GroupName.
The method I use is
var me = Bot.GetChatAsync(e.Message.Chat.Id).Result;
From doc this field User is optional for groups.
You can see who send message in e.Message.From, this property returns who send it as User.
And you should await methods that is awaitable.
And in your case Bot.GetChatAsync, this will return Chat from ChatId.
It means: Info about chat from Id.
And you pass Chat not ChatId to Bot.GetChatAsync

How to send message in the group using group name not a chat id on telegram bot using c#?

Hello every one i have right now go for the my app to sync with telegram bot.and i need to send some messages on group on the telegram bot.for ex. i have create one one group on the telegram bot like group name is "Rock" and my bot name is like "ABC". now i need to from my c# side need some create api and send message using group name. i have find many links but all link give idea with chat id. but i want work with group name.here i have create one api for the send message but it's working with chat id and not work for the group.
Here this is my api =>
[System.Web.Http.AcceptVerbs("GET", "POST")]
public void sendMessage(string destID, string text)
{
try
{
Bot.SendTextMessageAsync(destID, text);
}
catch (Exception e)
{
Console.WriteLine("err");
}
}
any one know how can do that please let me know. using group name i want to send message on telegram bot.
You can't use title as parameter to send message, think about two group have same name? :)
If you don't want to send via Chat ID, try group username.
Unique identifier for the target chat or username of the target channel (in the format #channelusername)
The group name isn't unique and telegram can't use that for sending a message. Because a name may be used for several groups. Which one should be selected?
You have no another option but if you want to simplify your code, you can store group-id as const variable:
public const double Rock= '164865465465';
and use like this:
SendMessage(Rock, text);

Read And Write To Header Message MQ C#

I am reading an MQMessage in like so
queue.Get(message, gmo);
string message1 = message.ReadString(message.MessageLength);
I can see there is a message.UserId on MQMessage, but that is not enough
I want the users to get additional information in the message header of an MQMessage.
How can I set and then retrieve the following from a header of an MQMessage
username
password
mySpecialID
This can be done like this
msg.SetStringProperty("NicksProp", "blahblah");
Note: MQ treats message properties as plain text, so if you are sending a password as a message property then EVERYONE can see it. You will be able to see it via WireShark, and/or in the queue with any tool (MQ Explorer) and/or in the MQ log files.

implementing "Reply this by email" for a ticket

I'm going to develop a ticketing system with c# that should send an email containing the ticket content to the receiver upon ticket submission and the receiver should be able to reply to that email which results in sender receiving the email of the reply. What puzzles me is that how am I going to keep track of that specific ticket which being replied by the receiver. I'm not looking for any code, just concepts or best practices.
Theoretically, you might use the Message-ID in conjunction with In-Reply-To, as described in the RFC 5322:
The "Message-ID:" field provides a unique message identifier that
refers to a particular version of a particular message. The
uniqueness of the message identifier is guaranteed by the host that
generates it (see below). This message identifier is intended to be
machine readable and not necessarily meaningful to humans. A message
identifier pertains to exactly one version of a particular message;
subsequent revisions to the message each receive new message
identifiers.
The "In-Reply-To:" and "References:" fields are used when
creating a reply to a message. They hold the message identifier of
the original message and the message identifiers of other messages
(for example, in the case of a reply to a message that was itself a
reply). The "In-Reply-To:" field may be used to identify the message
(or messages) to which the new message is a reply, while the
"References:" field may be used to identify a "thread" of
conversation.
When creating a reply to a message, the "In-Reply-To:" and
"References:" fields of the resultant message are constructed as
follows:
The "In-Reply-To:" field will contain the contents of the
"Message-ID:" field of the message to which this one is a reply (the
"parent message"). If there is more than one parent message, then the
"In-Reply-To:" field will contain the contents of all of the parents'
"Message-ID:" fields. If there is no "Message-ID:" field in any of the
parent messages, then the new message will have no "In-Reply-To:"
field.
Of course, you should keep tracking of mappings between the Message-ID field and you internal ticket number in a separate database table.
Example
A new email E1 is sent from yourCompany.com.
A reply R1 is received from yahoo.com. The message header information:
References:
<11111#yourCompany.com>
Message-ID:
<22222#webServer.yahoo.com>
In-Reply-To:
<11111#yourCompany.com>
A reply R2 to R1 is sent from yourCompany.com.
A reply R3 to R2 is received from yahoo.com. The message header information:
References:
<11111#yourCompany.com>
<22222#webServer.yahoo.com>
<33333#yourCompany.com>
Message-ID:
<44444#webServer.yahoo.com>
In-Reply-To:
<33333#yourCompany.com>
I think the only way to do this (and I never saw a ticketing-system who does that differently) is adding the ID into the subject-line.
In our case, we have subject-headers like "bla bla bla <<< CALLID: 12312 >>>".
With regex, that's quite easy to catch
Keep the ticket in the Subject in a specific format that the application can understand.
e.g. Subject can be Close TICKET T1 or
Reject Resolution TICKET T1 .
You can ask the customer to specify the reason in the mail body.
the trick is to give pre-formatted Subject which you understand.

Categories