Esempio n. 1
0
        static MediaMessage()
        {
            DOG = new MediaMessage();

            DOG.OriginalContentURL = "https://farm8.staticflickr.com/7822/46577101464_b8e1a7e1db_b.jpg";
            DOG.PreviewImageURL    = "https://farm8.staticflickr.com/7822/46577101464_b8e1a7e1db_m.jpg";
        }
Esempio n. 2
0
        //自訂解析JSON傳回物件的邏輯
        public override object ReadJson(JsonReader reader, Type objectType,
                                        object existingValue, JsonSerializer serializer)
        {
            JObject jo = JObject.Load(reader);
            //先取得JobType,由其決定建立物件
            string type = jo["type"].ToString();

            switch (type)
            {
            case Message.TEXT_TYPE:
                TextMessage text = new LineBot.Models.WebhookEvents.Message.TextMessage();
                serializer.Populate(jo.CreateReader(), text);
                return(text);

            case Message.IMAGE_TYPE:
            case Message.VIDEO_TYPE:
                MediaMessage media = new LineBot.Models.WebhookEvents.Message.MediaMessage();
                serializer.Populate(jo.CreateReader(), media);
                return(media);

            case Message.AUDIO_TYPE:
                AudioMessage audio = new LineBot.Models.WebhookEvents.Message.AudioMessage();
                serializer.Populate(jo.CreateReader(), audio);
                return(audio);

            case Message.LOCATION_TYPE:
                LocationMessage location = new LineBot.Models.WebhookEvents.Message.LocationMessage();
                serializer.Populate(jo.CreateReader(), location);
                return(location);

            case Message.STICER_TYPE:
                StickerMessage sticker = new LineBot.Models.WebhookEvents.Message.StickerMessage();
                serializer.Populate(jo.CreateReader(), sticker);
                return(sticker);

            default:
                throw new ApplicationException("Unsupported type: " + type);
            }
        }