Exemple #1
0
 internal static string ToActionString(this ChatAction action)
 {
     return(action.GetType()
            .GetRuntimeField(action.ToString())
            .GetCustomAttributes(typeof(EnumMemberAttribute), true)
            .Select(a => ((EnumMemberAttribute)a).Value).FirstOrDefault());
 }
Exemple #2
0
        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));
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
 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);
     }
 }
Exemple #5
0
 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);
     }
 }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        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);
        }