예제 #1
0
        private bool SetPhotoTemplate(MessageViewModel message, MessagePhoto photo, string title)
        {
            Visibility = Visibility.Visible;

            // 🖼

            SetTitle(GetFromLabel(message, title));
            SetService(Strings.Resources.AttachPhoto);
            SetMessage(string.Empty);

            if (message.Ttl > 0)
            {
                HideThumbnail();
            }
            else
            {
                ShowThumbnail();

                var small = photo.Photo.GetSmall();
                if (small != null)
                {
                    UpdateThumbnail(message, small);
                }
            }

            if (photo.Caption != null && !string.IsNullOrWhiteSpace(photo.Caption.Text))
            {
                AppendService(", ");
                AppendMessage(photo.Caption.Text.Replace("\r\n", "\n").Replace('\n', ' '));
            }

            return(true);
        }
예제 #2
0
        public void Mockup(MessagePhoto photo)
        {
            var big = photo.Photo.GetBig();

            Constraint     = photo;
            Background     = null;
            Texture.Source = new BitmapImage(new Uri(big.Photo.Local.Path));

            Overlay.Opacity = 0;
            Button.Opacity  = 0;
        }
예제 #3
0
 private static void Tr_MessagePhoto(object sendr, MessagePhoto <User, Chat> e)
 {
     //Console.WriteLine("ID сообщения:{0}\nID отправителя:{1}\nНик отправителя:{2}\nИмя:{3} Фамилия:{4}\nДата:{5}\nКомментарий к фотографии:{6}",
     //    e.message_id, e.from.id, e.from.username, e.from.first_name, e.from.last_name, e.date, e.caption);
     //for (int i = 0; i < e.photo.Count; i++)
     //{
     //    Console.WriteLine("Фото №{0}", i + 1);
     //    Console.WriteLine("ID Файла:{0}\nРазмер файла:{1}байт\nШирина:{2} Высота:{3}\n",
     //        e.photo[i].file_id, e.photo[i].file_size, e.photo[i].width, e.photo[i].height);
     //}
     //MethodBot m = new MethodBot(Settings.Default.Token);
     //m.SendMessage("Вы нам прислалим фотографию", 243746390);
     //m.SendPhotoLink(243746390, e.photo[e.photo.Count - 1].file_id, e.caption);
 }
예제 #4
0
        private void Tr_MessagePhoto(object sendr, MessagePhoto e)
        {
            Console.WriteLine("ID сообщения:{0}\nID отправителя:{1}\nНик отправителя:{2}\nИмя:{3} Фамилия:{4}\nДата:{5}\nКомментарий к фотографии:{6}",
                              e.message_id, e.from.id, e.from.username, e.from.first_name, e.from.last_name, e.date, e.caption);
            for (int i = 0; i < e.photo.Count; i++)
            {
                Console.WriteLine("Фото №{0}", i + 1);
                Console.WriteLine("ID Файла:{0}\nРазмер файла:{1}байт\nШирина:{2} Высота:{3}\n",
                                  e.photo[i].file_id, e.photo[i].file_size, e.photo[i].width, e.photo[i].height);
            }
            Method m = new Method(MainSettings.Default.Token, MainSettings.Default.API_URL);

            m.SendMessage("Вы нам прислалим фотографию", e.chat.id);
            m.SendPhoto_link(e.chat.id, e.photo[e.photo.Count - 1].file_id, e.caption);
        }
예제 #5
0
        public static MessagePhoto GetPhoto(TelegramBotClient bot, Message mes, PhotoQuality quality = PhotoQuality.High)
        {
            if (bot == null ||
                mes == null ||
                mes.Type != MessageType.Photo)
            {
                return(null);
            }

            int    qualityIndex = (int)Math.Round(((int)quality) / ((double)PhotoQuality.High) * mes.Photo.Length - 1);
            string fileId       = null;

            fileId = mes.Photo[qualityIndex].FileId;
            MessagePhoto photo = new MessagePhoto();

            photo.File = GetFile(bot, mes, fileId);
            return(photo);
        }
예제 #6
0
        private bool SetPhotoTemplate(MessageViewModel message, MessagePhoto photo, string title)
        {
            Visibility = Visibility.Visible;

            // 🖼

            TitleLabel.Text   = GetFromLabel(message, title);
            ServiceLabel.Text = Strings.Resources.AttachPhoto;
            MessageLabel.Text = string.Empty;

            if (message.Ttl > 0)
            {
                if (ThumbRoot != null)
                {
                    ThumbRoot.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                FindName(nameof(ThumbRoot));
                if (ThumbRoot != null)
                {
                    ThumbRoot.Visibility = Visibility.Visible;
                }

                ThumbRoot.CornerRadius = ThumbEllipse.CornerRadius = default(CornerRadius);
                //ThumbImage.ImageSource = (ImageSource)DefaultPhotoConverter.Convert(photoMedia, true);

                var small = photo.Photo.GetSmall();
                if (small != null)
                {
                    UpdateThumbnail(message, small);
                }
            }

            if (photo.Caption != null && !string.IsNullOrWhiteSpace(photo.Caption.Text))
            {
                ServiceLabel.Text += ", ";
                MessageLabel.Text += photo.Caption.Text.Replace("\r\n", "\n").Replace('\n', ' ');
            }

            return(true);
        }
 public static bool UpdateFile(this MessagePhoto photo, File file)
 {
     return(photo.Photo.UpdateFile(file));
 }
예제 #8
0
 public OutboxMessage(MessagePhoto photo) : this((object)photo)
 {
     this.Type = OutboxMessageType.Photo;
 }
예제 #9
0
 private static void Tr_MessagePhoto(object sendr, MessagePhoto <User, Chat> e)
 {
 }
예제 #10
0
파일: Test.cs 프로젝트: Saley97/salehack
    private void Update()
    {
//        if (isFlag)
//        {
//            Debug.Log("User data:");
//            Debug.Log(testUser.GetJson());
//            MessageUser msgSend = new MessageUser(testUser.GetJson());
//            Debug.Log("Message Sended:");
//            Debug.Log(msgSend.GetSerializedMessage());
//
//            MessageUser msgGet = JsonConvert.DeserializeObject<MessageUser>(msgSend.GetSerializedMessage());
//            Debug.Log("Message Geted:");
//            Debug.Log(msgGet?.GetSerializedMessage());
//
//            User getedUser = msgGet.GetObject() as User;
//            Debug.Log("Geted user data:");
//            Debug.Log(getedUser.GetJson());
//
//            isFlag = false;
//        }

        if (isFlag)
        {
//            RestClient.Get(config.ServerPath).Then(response =>
//            {
//                Debug.Log(/*JsonConvert.DeserializeObject<MessageUser>*/(response.Text));
//            }).Catch(error =>
//            {
//                Debug.Log(error.Message);
//            });
//
//            isFlag = false;
            //MessageUser msgSend = new MessageUser(testUser.GetJson());

            MessagePhoto msgPhoto = new MessagePhoto(
                new Photo()
            {
                id          = 6,
                width       = testSprite.texture.width,
                height      = testSprite.texture.height,
                format      = testSprite.texture.format,
                mipmapCount = testSprite.texture.mipmapCount,
                //texture = testSprite.texture,
                data = testSprite.texture.GetRawTextureData()
            }.GetJson());

            RestClient.Request(
                new RequestHelper()
            {
                Uri     = config.ServerPath,
                Method  = "POST",
                Timeout = 100,
                //Body = msgPhoto,
                BodyString = msgPhoto.GetSerializedMessage(),
                //Body = testUser,
                DownloadHandler = new DownloadHandlerFile(Application.dataPath + "/test.json")     //Send bytes directly if it's required  DownloadHandler = new DownloadHandlerFile(destPah)
            }
                ).Then(response =>
            {
                Debug.Log("Success");
                imgFlag = true;
            }).Catch(error =>
            {
                Debug.Log(error.Message);
            });

            isFlag = false;
        }

        if (imgFlag)
        {
            MessagePhoto rMsg    = JsonConvert.DeserializeObject <MessagePhoto>(File.ReadAllText(Application.dataPath + "/test.json")) as MessagePhoto;
            Photo        photo   = rMsg.GetObject() as Photo;
            Texture2D    texture = new Texture2D(photo.width, photo.height, photo.format, photo.mipmapCount > 1);
            texture.LoadRawTextureData(photo.data);
            //texture.Apply();
            Debug.Log(photo.data.Length);
            //Debug.Log(ImageConversion.LoadImage(texture, rPhoto.data, false));
            texture.Apply();
            img.sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);

            imgFlag = false;
        }
    }
        private static async void SendOutboxMessageToChat(this TelegramBotClient bot, ChatId chatId, OutboxMessage message)
        {
            if (bot == null ||
                ((chatId == null || chatId?.Identifier == 0) &&
                 string.IsNullOrEmpty(chatId?.Username)))
            {
                throw new ArgumentNullException();
            }

            switch (message.Type)
            {
            //Send Text
            case OutboxMessageType.Text:
                await bot.SendTextMessageAsync(
                    chatId : chatId,
                    text : (string)message.Data,
                    replyMarkup : message.ReplyMarkup,
                    parseMode : message.ParseMode,
                    replyToMessageId : message.ReplyToMessageId);

                break;

            //Send MessagePhoto Entity
            case OutboxMessageType.Photo:
                MessagePhoto photo = (MessagePhoto)message.Data;
                await bot.SendPhotoAsync(
                    chatId : chatId,
                    photo : new InputOnlineFile(photo.File.Stream),
                    caption : photo.Caption,
                    replyToMessageId : message.ReplyToMessageId,
                    parseMode : message.ParseMode);

                break;

            //Send MessageAudio Entity
            case OutboxMessageType.Audio:
                MessageAudio audio = (MessageAudio)message.Data;
                await bot.SendAudioAsync(
                    chatId : chatId,
                    audio : new InputOnlineFile(audio.File.Stream),
                    caption : audio.Caption,
                    replyMarkup : message.ReplyMarkup,
                    replyToMessageId : message.ReplyToMessageId,
                    thumb : audio.Thumb,
                    title : audio.Title,
                    parseMode : message.ParseMode);

                break;

            //Send MessageVoice Entity
            case OutboxMessageType.Voice:
                MessageVoice voice = (MessageVoice)message.Data;
                await bot.SendVoiceAsync(
                    chatId : chatId,
                    voice : new InputOnlineFile(voice.File.Stream),
                    replyMarkup : message.ReplyMarkup,
                    replyToMessageId : message.ReplyToMessageId,
                    caption : voice.Caption,
                    parseMode : message.ParseMode);

                break;

            //ToDo other Types of message!
            default:
                throw new Exception("Не поддерживаемый тип отправки сообщений");
                break;
            }

            //Рекурсивно вызываем отправку вложенных элементов сообщения.
            foreach (var item in message.NestedElements)
            {
                SendOutboxMessageToChat(bot, chatId, item);
            }
        }