コード例 #1
0
        protected void Button5_Click(object sender, EventArgs e)
        {
            //建立Bot instance
            isRock.LineBot.Bot bot =
                new isRock.LineBot.Bot(channelAccessToken);  //傳入Channel access token

            //建立actions,作為ButtonTemplate的用戶回覆行為
            var actions = new List <isRock.LineBot.TemplateActionBase>();

            actions.Add(new isRock.LineBot.MessageActon()
            {
                label = "標題-文字回覆", text = "回覆文字"
            });
            actions.Add(new isRock.LineBot.UriActon()
            {
                label = "標題-Google", uri = new Uri("http://www.google.com")
            });
            actions.Add(new isRock.LineBot.PostbackActon()
            {
                label = "標題-發生postack", data = "abc=aaa&def=111"
            });

            //單一Column
            var Column = new isRock.LineBot.Column
            {
                text  = "ButtonsTemplate文字訊息",
                title = "ButtonsTemplate標題",
                //設定圖片
                thumbnailImageUrl = new Uri("https://arock.blob.core.windows.net/blogdata201706/22-124357-ad3c87d6-b9cc-488a-8150-1c2fe642d237.png"),
                actions           = actions //設定回覆動作
            };

            //建立CarouselTemplate
            var CarouselTemplate = new isRock.LineBot.CarouselTemplate();

            //這是範例,所以用一組樣板建立三個
            CarouselTemplate.columns.Add(Column);
            CarouselTemplate.columns.Add(Column);
            CarouselTemplate.columns.Add(Column);
            //發送 CarouselTemplate
            bot.PushMessage(AdminUserId, CarouselTemplate);
        }
コード例 #2
0
ファイル: LineTemplate.cs プロジェクト: kbc6s/linebot227
        // 遠端控制Carousel
        public static void CarouselTemplateTest(ButtonTemplateParameter ButtonTemplateParameter)
        {
            RestAPI api = new RestAPI();
            var     bot = new Bot(channelAccessToken);
            //建立actions,作為ButtonTemplate的用戶回覆行為
            //=======6F==========
            var actions6 = new List <isRock.LineBot.TemplateActionBase>();

            actions6.Add(new isRock.LineBot.MessageAction()
            {
                label = "開啟6F大門", text = "開六樓的門"
            });
            actions6.Add(new isRock.LineBot.MessageAction()
            {
                label = "6F工程部空調(" + api.GetValue("020013") + "度)", text = "開啟6樓工程部空調"
            });
            actions6.Add(new isRock.LineBot.MessageAction()
            {
                label = "6F業務部空調(" + api.GetValue("020014") + "度)", text = "開啟6樓系統部空調"
            });

            //=======4F==========
            var actions4 = new List <isRock.LineBot.TemplateActionBase>();

            actions4.Add(new isRock.LineBot.MessageAction()
            {
                label = "4F大門", text = "開四樓的門"
            });
            actions4.Add(new isRock.LineBot.MessageAction()
            {
                label = "4樓會議室空調(" + api.GetValue("010013") + "度)", text = "開啟4樓會議室空調"
            });
            actions4.Add(new isRock.LineBot.MessageAction()
            {
                label = "4樓組盤間空調(" + api.GetValue("010014") + "度)", text = "開啟4樓組盤間空調"
            });
            //=======266==========
            var actions266 = new List <isRock.LineBot.TemplateActionBase>();

            actions266.Add(new isRock.LineBot.MessageAction()
            {
                label = "266大門", text = "開266的門"
            });
            actions266.Add(new isRock.LineBot.MessageAction()
            {
                label = "266", text = "266沒空調喔@@"
            });
            actions266.Add(new isRock.LineBot.MessageAction()
            {
                label = "6F工程部空調(" + api.GetValue("020013") + "度)", text = "開啟6樓工程部空調"
            });

            //依照冷氣狀態改變圖案
            string imgURL = "";

            if (api.GetValue("020001") == 1)
            {
                imgURL = "https://cdn4.iconfinder.com/data/icons/hotel-service-5/300/air_conditioner-512.png"; //冷氣運作圖
            }
            else
            {
                imgURL = "https://cdn2.iconfinder.com/data/icons/kitchen-appliances-computers-and-electronics/32/Appliances-19-128.png"; //冷氣圖
            }
            //製作模板框架
            // =======6樓=======
            var ButtonTemplate6F = new isRock.LineBot.Column
            {
                text = "6樓",
                //title = "6樓",
                //設定圖片
                thumbnailImageUrl = new Uri(imgURL),
                actions           = actions6 //設定回覆動作
            };
            //======= 4樓 =======
            var ButtonTemplate4F = new isRock.LineBot.Column
            {
                text = "4樓",
                //title = "4樓",

                //設定圖片
                thumbnailImageUrl = new Uri("https://cdn3.iconfinder.com/data/icons/letters-and-numbers-1/32/number_4_green-256.png"),
                actions           = actions4 //設定回覆動作
            };
            //=========266======
            var ButtonTemplate266 = new isRock.LineBot.Column
            {
                text = "266",
                //title = "266",

                //設定圖片
                thumbnailImageUrl = new Uri("https://cdn2.iconfinder.com/data/icons/essential-web-5/50/setting-adjust-control-panel-equalizer-256.png"),
                actions           = actions266 //設定回覆動作
            };
            var CarouselTemplate = new isRock.LineBot.CarouselTemplate();

            CarouselTemplate.columns.Add(ButtonTemplate6F);
            CarouselTemplate.columns.Add(ButtonTemplate4F);
            CarouselTemplate.columns.Add(ButtonTemplate266);
            //發送
            bot.PushMessage(ButtonTemplateParameter.LineID, CarouselTemplate);
        }