public void HandleMessage(RequestMessage message) { bool handledAsAsmin = false; if (message.ChatId == AdminUserChatId()) { string[] tokens = message.Message.Split(' '); if (tokens.Length == 3) { long param = 0; if (tokens[0] == "추가" && long.TryParse(tokens[1], out param)) { string[] exclusionStrings = tokens[2].Split(','); HashSet <ContentType> exclusions = new HashSet <ContentType>(); foreach (string ex in exclusionStrings) { ContentType ct = ContentTypeConverter.StringToContentType(ex); if (ct == ContentType.UNSPECIFIED) { string error = String.Format("올바르지 않은 이름입니다 : {0}", ex); ResponseQueue.Enqueue(new HashSet <long>() { message.ChatId }, error); return; } else { exclusions.Add(ct); } } if (AddSubscriber(param, exclusions)) { handledAsAsmin = true; ResponseQueue.Enqueue(new HashSet <long>() { message.ChatId }, "추가하였습니다"); } } } } if (!handledAsAsmin) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("당신의 텔레그램 ChatId 는 {0} 입니다.\n이 봇은 등록된 사용자만 사용가능합니다.", message.ChatId); sb.AppendFormat("\n\nYour Telegram ChatId is {0}.\nThis bot is for registered users only.", message.ChatId); ResponseQueue.Enqueue(new HashSet <long>() { message.ChatId }, sb.ToString()); } }
private void SendImageLinks(HashSet <long> receivers, KidsNoteContent content) { LinkedList <string> imageLinks = new LinkedList <string>(); foreach (var attach in content.Attachments) { if (IsImageAttachment(attach) && attach.ImageSource != "") { imageLinks.AddLast(attach.ImageSource); } } foreach (var user in receivers) { foreach (var attach in content.Attachments) { if (IsImageAttachment(attach) && attach.DownloadUrl != "") { // 일반 이미지 if (attach.Type == AttachmentType.IMAGE) { try { string link = attach.DownloadUrl.IndexOf("%") >= 0 ? attach.ImageSource : attach.DownloadUrl; string originalLink = attach.DownloadUrl.Replace("&", "&"); string message = String.Format("사진을 전송합니다. 잠시 기다리시면 미리보기가 나타납니다.\n\n{0}", link); message += String.Format("\n\n깨끗한 사진을 보시리면 아래 링크를 클릭하세요.\n\n{0}", originalLink); var task = TheClient.SendTextMessageAsync(user, message); task.Wait(); } catch (Exception) { } } else // 식단표 { try { string menuType = ContentTypeConverter.AttachmentLunchTypeToString(attach.Type); StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} : {1}\n\n", menuType, attach.Description); sb.Append(attach.DownloadUrl); var task = TheClient.SendTextMessageAsync(user, sb.ToString()); task.Wait(); } catch (Exception) { } } } } } }