Пример #1
0
        //遠端控制
        public static void RemoteController(ButtonTemplateParameter ButtonTemplateParameter)
        {
            var bot = new Bot(channelAccessToken);
            //建立actions,作為ButtonTemplate的用戶回覆行為
            var actions = new List <isRock.LineBot.TemplateActionBase>();

            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "空調控制postback", data = "123456789"
            });                                                  //ButtonTemplateParameter.postback.ToString()
            actions.Add(new isRock.LineBot.MessageAction()
            {
                label = "6F 空調", text = ButtonTemplateParameter.LineEvent
            });


            //單一Button Template Message
            var ButtonTemplate = new isRock.LineBot.ButtonsTemplate()
            {
                altText = "監看狀態",
                text    = ButtonTemplateParameter.Title,
                //title = "Title",

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

            //發送
            bot.PushMessage(ButtonTemplateParameter.LineID, ButtonTemplate);
        }
Пример #2
0
        //樓宇監控模板
        public static void BuildingStatusTemplete(ButtonTemplateParameter ButtonTemplateParameter)
        {
            var bot = new Bot(channelAccessToken);
            //建立actions,作為ButtonTemplate的用戶回覆行為
            var actions = new List <isRock.LineBot.TemplateActionBase>();

            actions.Add(new isRock.LineBot.UriAction()
            {
                label = "6F 監看", uri = new Uri(ButtonTemplateParameter.ViewURL1)
            });
            actions.Add(new isRock.LineBot.UriAction()
            {
                label = "4F 監看", uri = new Uri(ButtonTemplateParameter.ViewURL2)
            });
            //actions.Add(new isRock.LineBot.PostbackAction()
            //{ label = "空調控制postback", data = "123456789" });


            //單一Button Template Message
            var ButtonTemplate = new isRock.LineBot.ButtonsTemplate()
            {
                altText = "監看狀態",
                text    = "樓宇監看",
                //title = "Title",

                //設定圖片
                thumbnailImageUrl = new Uri("https://cdn0.iconfinder.com/data/icons/linkedin-ui-colored/48/JD-12-512.png"),
                actions           = actions //設定回覆動作
            };

            //發送
            bot.PushMessage(ButtonTemplateParameter.LineID, ButtonTemplate);
        }
Пример #3
0
        //首次登入模板
        public static void LoginTemplete(ButtonTemplateParameter ButtonTemplateParameter)
        {
            var bot = new Bot(channelAccessToken);
            //建立actions,作為ButtonTemplate的用戶回覆行為
            var actions = new List <isRock.LineBot.TemplateActionBase>();

            //actions.Add(new isRock.LineBot.MessageAction()
            //{ label = "首次登入", text = "首次登入" });
            //actions.Add(new isRock.LineBot.MessageAction()
            //{ label = "點選這邊等同用戶直接輸入某訊息", text = ButtonTemplateFunction.LineEvent });
            actions.Add(new isRock.LineBot.UriAction()
            {
                label = "首次登入", uri = new Uri("https://ddb9e636.ngrok.io/login.aspx?name=" + ButtonTemplateParameter.LineID)
            });
            //actions.Add(new isRock.LineBot.UriAction()
            //{ label = "設定推播訊息", uri = new Uri(https://9e90d783.ngrok.io/WebForm1.aspx" + ButtonTemplateParameter.LineID) });
            actions.Add(new isRock.LineBot.MessageAction()
            {
                label = "設定推播訊息", text = "還沒做好喔@@"
            });



            //單一Button Template Message
            var ButtonTemplate = new isRock.LineBot.ButtonsTemplate()
            {
                altText = "個人設定",
                text    = "Text",
                //title = "Title",
                //設定圖片
                thumbnailImageUrl = new Uri("https://cdn0.iconfinder.com/data/icons/linkedin-ui-colored/48/JD-12-512.png"),
                actions           = actions //設定回覆動作
            };

            //發送
            bot.PushMessage(ButtonTemplateParameter.LineID, ButtonTemplate);
        }
Пример #4
0
        // 遠端控制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);
        }
        public IHttpActionResult POST()
        {
            //設定允許控制的星期
            var week = new List <string> {
                "週一", "週二", "週三", "週四", "週五", "週六"
            };
            var sql = new SQLcontroller("192.168.3.247", "mydb", "leegood", "leegood");
            ScheduleControll time = new ScheduleControll();
            RestAPI          api  = new RestAPI();

            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent = this.ReceivedMessage.events.FirstOrDefault();
                //配合Line verify
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                //回覆訊息
                if (LineEvent.type == "postback")
                {
                    string msg = LineEvent.postback.data;
                    //msg += $"\n Params.date : {LineEvent.postback.Params.date + ""}";
                    //msg += $"\n Params.datetime : {LineEvent.postback.Params.datetime + ""}";
                    //msg += $"\n Params.time : {LineEvent.postback.Params.time + ""}";
                    this.ReplyMessage(LineEvent.replyToken, msg);
                    return(Ok());
                }

                if (LineEvent.type == "message")
                {
                    if (LineEvent.message.type == "text")
                    { //收到文字
                      //this.ReplyMessage(LineEvent.replyToken, "你說了:" + LineEvent.message.text);

                        if (LineEvent.message.text == "個人設定")
                        {
                            ButtonTemplateParameter info = new ButtonTemplateParameter();
                            info.LineID = LineEvent.source.userId;
                            linebot227.Functions.LineTemplate.LoginTemplete(info);
                        }

                        if (LineEvent.message.text == "監看狀態" && check.VeriMember(LineEvent.source.userId))
                        {
                            ButtonTemplateParameter status = new ButtonTemplateParameter();
                            status.LineID   = LineEvent.source.userId;
                            status.ViewURL1 = "http://api.leegood.com.tw:58088/LGoffice_/home.htm";
                            status.ViewURL2 = "http://api.leegood.com.tw:58088/LGoffice_/4f_sa.htm";
                            LineTemplate.BuildingStatusTemplete(status);
                        }
                        if (LineEvent.message.text == "遠端控制" && check.VeriMember(LineEvent.source.userId))
                        {
                            ButtonTemplateParameter status = new ButtonTemplateParameter
                            {
                                LineID = LineEvent.source.userId
                            };
                            LineTemplate.CarouselTemplateTest(status);
                        }
                        if (LineEvent.message.text == "開啟6樓系統部空調" && check.VeriMember(LineEvent.source.userId))
                        {
                            LogInfo log = new LogInfo();
                            log.AuthTime = DateTime.Now;
                            log.Event    = "Open6FX-TeamAircon";
                            log.LineID   = LineEvent.source.userId;
                            sql.InsertLogTime(log);
                            var isOpenTime = time.Schedule(week, 9, 24, LineEvent.source.userId);
                            if (isOpenTime)
                            {
                                if (api.GetValue("020004") == 1)
                                {
                                    this.ReplyMessage(LineEvent.replyToken, "系統部冷氣是開著的喔.....");
                                }
                                else
                                {
                                    api.SetValue("020032", 1);
                                    Thread.Sleep(800);         //Delay 1秒
                                    api.SetValue("020032", 0); //020032
                                    if (api.GetValue("020004") == 1)
                                    {
                                        this.ReplyMessage(LineEvent.replyToken, "成功開啟空調");
                                    }
                                }
                            }
                        }
                        if (LineEvent.message.text == "開啟6樓工程部空調" && check.VeriMember(LineEvent.source.userId))
                        {
                            LogInfo log = new LogInfo();
                            log.AuthTime = DateTime.Now;
                            log.Event    = "Open6FEngineerAircon";
                            log.LineID   = LineEvent.source.userId;
                            sql.InsertLogTime(log);
                            var isOpenTime = time.Schedule(week, 9, 24, LineEvent.source.userId);
                            if (isOpenTime)
                            {
                                if (api.GetValue("020001") == 1)
                                {
                                    this.ReplyMessage(LineEvent.replyToken, "工程部冷氣是開著的喔.....");
                                }
                                else
                                {
                                    api.SetValue("020031", 1);
                                    Thread.Sleep(800);         //Delay 1秒
                                    api.SetValue("020031", 0); //020032
                                    if (api.GetValue("020001") == 1)
                                    {
                                        this.ReplyMessage(LineEvent.replyToken, "成功開啟空調");
                                    }
                                }
                            }
                        }
                        if (LineEvent.message.text == "開啟4樓會議室空調" && check.VeriMember(LineEvent.source.userId))
                        {
                            LogInfo log = new LogInfo();
                            log.AuthTime = DateTime.Now;
                            log.Event    = "Open4FConferenceRoomAircon";
                            log.LineID   = LineEvent.source.userId;
                            sql.InsertLogTime(log);
                            var isOpenTime = time.Schedule(week, 9, 24, LineEvent.source.userId);
                            if (isOpenTime)
                            {
                                if (api.GetValue("010001") == 1)
                                {
                                    this.ReplyMessage(LineEvent.replyToken, "4F會議室冷氣是開著的喔.....");
                                }
                                else
                                {
                                    api.SetValue("010031", 1);
                                    Thread.Sleep(800);
                                    api.SetValue("010031", 0);
                                    if (api.GetValue("010001") == 1)
                                    {
                                        this.ReplyMessage(LineEvent.replyToken, "成功開啟空調");
                                    }
                                }
                            }
                        }
                        if (LineEvent.message.text == "開啟4樓組盤間空調" && check.VeriMember(LineEvent.source.userId))
                        {
                            LogInfo log = new LogInfo();
                            log.AuthTime = DateTime.Now;
                            log.Event    = "Open4FDIYRoomAircon";
                            log.LineID   = LineEvent.source.userId;
                            sql.InsertLogTime(log);
                            var isOpenTime = time.Schedule(week, 9, 24, LineEvent.source.userId);
                            if (isOpenTime)
                            {
                                if (api.GetValue("010004") == 1)
                                {
                                    this.ReplyMessage(LineEvent.replyToken, "4樓組盤間冷氣是開著的喔");
                                }
                                else
                                {
                                    api.SetValue("010032", 1);
                                    Thread.Sleep(800);         //Delay 1秒
                                    api.SetValue("010032", 0); //020032
                                    if (api.GetValue("010004") == 1)
                                    {
                                        this.ReplyMessage(LineEvent.replyToken, "成功開啟空調");
                                    }
                                    else
                                    {
                                        this.ReplyMessage(LineEvent.replyToken, "失敗");
                                    }
                                }
                            }
                        }
                        if (LineEvent.message.text == "4444" && check.VeriMember(LineEvent.source.userId))
                        {
                            LogInfo log = new LogInfo();
                            log.AuthTime = DateTime.Now;
                            log.Event    = "Open4FDoor";
                            log.LineID   = LineEvent.source.userId;
                            sql.InsertLogTime(log);
                            var isOpenTime = time.Schedule(week, 9, 24, LineEvent.source.userId);
                            if (isOpenTime)
                            {
                                api.SetValue("010007", 1);
                                Thread.Sleep(800);         //Delay 1秒
                                api.SetValue("010007", 0); //020032
                            }
                        }
                        if (LineEvent.message.text == "6666" && check.VeriMember(LineEvent.source.userId))
                        {
                            LogInfo log = new LogInfo();
                            log.AuthTime = DateTime.Now;
                            log.Event    = "Open6FDoor";
                            log.LineID   = LineEvent.source.userId;
                            sql.InsertLogTime(log);
                            var isOpenTime = time.Schedule(week, 9, 24, LineEvent.source.userId);
                            if (isOpenTime)
                            {
                                api.SetValue("020007", 1);
                                Thread.Sleep(800);         //Delay 1秒
                                api.SetValue("020007", 0); //020032
                            }
                        }
                        if (LineEvent.message.text == "檢查門窗" && check.VeriMember(LineEvent.source.userId))
                        {
                            //RestAPI api = new RestAPI();
                            LogInfo log = new LogInfo();
                            log.AuthTime = DateTime.Now;
                            log.Event    = "checkDoor";
                            log.LineID   = LineEvent.source.userId;
                            sql.InsertLogTime(log);
                            var pointName = new List <string>
                            {
                                //6樓
                                "6樓大門,",
                                "志中旁窗戶,",
                                "柏欽旁窗戶,",
                                "禹任旁窗戶,",
                                "蕭董辦公室沙發旁,",
                                "蕭座位旁窗戶,",
                                "系統部窗戶,",
                                "小房間",
                                "測試點,",
                                //4樓
                                "4F大門,",
                                "組盤間,",
                                "測試間窗-1,",
                                "羅小姐辦公室窗-1,",
                                "羅小姐辦公室窗-2,",
                                "小會議室窗,",
                                "鄭總辦公室窗,",
                                "測試間窗-2"
                            };
                            var points = new List <string>
                            {
                                //6樓
                                "020030",          //大門        value是1代表門是開的
                                "BA_020023",       //志中旁窗戶
                                "BA_020024",       //柏欽旁窗戶
                                "BA_020025",       //禹任旁窗戶
                                "BA_020026",       //蕭董辦公室沙發旁
                                "BA_020027",       //蕭座位旁窗戶
                                "BA_020028",       //系統部窗戶
                                "BA_020029",       //小房間
                                "DO1",             //測試點
                                //4樓
                                "010127",
                                "BA_010121",
                                "BA_010122",
                                "BA_010123",
                                "BA_010124",
                                "BA_010125",
                                "BA_010126",
                                "BA_010128"
                            };
                            this.ReplyMessage(LineEvent.replyToken, api.GetListValue(points, pointName));
                            //bool isIn = points.Contains(1);
                            //string openStatus = "";
                            //int count = 0;
                            //if (isIn)
                            //{
                            //    foreach (var point in points)
                            //    {
                            //        count++;
                            //        if (point == 1)
                            //        {
                            //            openStatus += pointName[count - 1];
                            //        }
                            //    }
                            //    this.ReplyMessage(LineEvent.replyToken, openStatus+"沒關");
                            //}
                            //else
                            //{
                            //    this.ReplyMessage(LineEvent.replyToken, "門窗都關好了");
                            //}
                        }
                    }


                    if (LineEvent.message.type == "sticker") //收到貼圖
                    {
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    }
                }
                //response OK
                return(Ok());
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }