internal static string ToActionString(this ChatAction action) { return(action.GetType() .GetRuntimeField(action.ToString()) .GetCustomAttributes(typeof(EnumMemberAttribute), true) .Select(a => ((EnumMemberAttribute)a).Value).FirstOrDefault()); }
public async Task <bool> SendChatAction(long chatId, ChatAction action) { var parameters = new Dictionary <string, object> { { "chat_id", chatId }, { "action", action.ToString() } }; return(await SendWebRequest <bool>("sendChatAction", parameters)); }
/// <summary> /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). /// </summary> /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param> /// <param name="chatAction">Type of action to broadcast. Choose one, depending on what the user is about to receive.</param> /// <remarks>We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.</remarks> public async Task SendChatAction(int chatId, ChatAction chatAction) { var parameters = new Dictionary <string, object> { { "chat_id", chatId }, { "action", chatAction.ToString() } }; await SendWebRequest("sendChatAction", parameters).ConfigureAwait(false); }
public void SendChatAction(int chatID, ChatAction action) { using (WebClient webClient = new WebClient()) { NameValueCollection pars = new NameValueCollection(); pars.Add("chat_id", chatID.ToString()); pars.Add("action", action.ToString()); webClient.UploadValues("https://api.telegram.org/bot" + _token + "/sendChatAction", pars); } }
public void SendChatAction(int _chatID, ChatAction _action) { using (WebClient webClient = new WebClient()) { NameValueCollection pars = new NameValueCollection { { "chat_id", _chatID.ToString() }, { "action", _action.ToString() } }; webClient.UploadValues("https://api.telegram.org/bot" + Token + "/sendChatAction", pars); } }
/// <summary> /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). /// </summary> /// <param name="chatId">Unique identifier for the message recipient — User or GroupChat id</param> /// <param name="chatAction">Type of action to broadcast. Choose one, depending on what the user is about to receive.</param> /// <remarks>We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.</remarks> public async Task SendChatAction(int chatId, ChatAction chatAction) { const string method = "sendChatAction"; var parameters = new Dictionary <string, object> { { "chat_id", chatId }, { "action", chatAction.ToString() } }; await SendWebRequest(method, parameters); }
public static string GetActionValue(ChatAction action) { var type = typeof(ChatAction); var fieldInfoArr = type.GetFields(); var fieldInfo = fieldInfoArr.First(i => i.Name == action.ToString()); if (fieldInfo == null) { throw new ArgumentException($"The class {type} has no field {action}.", nameof(action)); } var attribute = (ChatActionAttribute)fieldInfo.GetCustomAttribute(typeof(ChatActionAttribute)); return(attribute.Action); }