예제 #1
0
        //ConfirmTemplate
        protected void Button2_Click(object sender, EventArgs e)
        {
            var bot = new isRock.LineBot.Bot(channelAccessToken);

            var CarouselTmpMsg = new isRock.LineBot.ConfirmTemplate()
            {
                text    = "文字",
                altText = "替代文字",
            };
            //add actions
            var action1 = new isRock.LineBot.MessageAction()
            {
                label = "OK", text = "呈現的文字"
            };

            CarouselTmpMsg.actions.Add(action1);

            var action2 = new isRock.LineBot.UriAction()
            {
                label = "NO", uri = new Uri("http://www.google.com")
            };

            CarouselTmpMsg.actions.Add(action2);

            bot.PushMessage(AdminUserId, CarouselTmpMsg);
        }
예제 #2
0
        protected void Button4_Click(object sender, EventArgs e)
        {
            var bot = new Bot(channelAccessToken);

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

            actions.Add(new isRock.LineBot.MessageActon()
            {
                label = "Yes", text = "Yes"
            });
            actions.Add(new isRock.LineBot.MessageActon()
            {
                label = "No", text = "No"
            });

            var ConfirmTemplate = new isRock.LineBot.ConfirmTemplate()
            {
                text    = "請選擇其中之一",
                altText = "請在手機上檢視",
                actions = actions
            };

            bot.PushMessage(AdminUserId, ConfirmTemplate);
        }
예제 #3
0
        internal static ConfirmTemplate MakeDeletOrderItem(string message, int QIDnow, int OIDnow, string BuyerInfoID, string userId, string channelAccessToken)
        {
            var            actions            = new List <isRock.LineBot.TemplateActionBase>();
            NextHelper     nextHelper         = new NextHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailNext = nextHelper.GetNext();

            CancelHelper   cancelHelper         = new CancelHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailCancel = cancelHelper.GetCancel();

            BuyerInfo buyerInfo = new BuyerInfo();

            buyerInfo.ID = int.Parse(BuyerInfoID);
            buyerInfo.SelectAllByBuyerInfoID();

            message = "缺定要刪除?";

            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "確定", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},{BuyerInfoID}"
            });
            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "取消", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},{buyerInfo.Item},{BuyerInfoID}"
            });
            var ConfirmTemplateMsg = new isRock.LineBot.ConfirmTemplate()
            {
                altText = "替代文字(在無法顯示Confirm Template的時候顯示)",
                text    = message,
                actions = actions //設定回覆動作
            };

            return(ConfirmTemplateMsg);
        }
예제 #4
0
        internal static ConfirmTemplate MakeDeleteMyOnceOrderConfirmBtn(string message, int QIDnow, int OIDnow, string UserIDorClubIDorOrderID)
        {
            var            actions            = new List <isRock.LineBot.TemplateActionBase>();
            NextHelper     nextHelper         = new NextHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailNext = nextHelper.GetNext();

            CancelHelper   cancelHelper         = new CancelHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailCancel = cancelHelper.GetCancel();

            string confirmText = GetConfirmText(QIDnow, OIDnow, UserIDorClubIDorOrderID);

            if (confirmText == "")
            {
                confirmText = message;
            }

            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "確定", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},MyOnceOrder"
            });
            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "取消", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
            });
            var ConfirmTemplateMsg = new isRock.LineBot.ConfirmTemplate()
            {
                altText = "替代文字(在無法顯示Confirm Template的時候顯示)",
                text    = confirmText,
                actions = actions //設定回覆動作
            };

            return(ConfirmTemplateMsg);
        }
예제 #5
0
        internal static ConfirmTemplate MakeNoteConfirmBtn(int QIDnow, int OIDnow)
        {
            var            actions            = new List <isRock.LineBot.TemplateActionBase>();
            NextHelper     nextHelper         = new NextHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailNext = nextHelper.GetNext();

            CancelHelper   cancelHelper         = new CancelHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailCancel = cancelHelper.GetCancel();

            string confirmText = "請問你需要寫個備註嗎??";

            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "不用哦~", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
            });
            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "填寫備註", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
            });
            var ConfirmTemplateMsg = new isRock.LineBot.ConfirmTemplate()
            {
                altText = "替代文字(在無法顯示Confirm Template的時候顯示)",
                text    = confirmText,
                actions = actions //設定回覆動作
            };

            return(ConfirmTemplateMsg);
        }
예제 #6
0
        internal static ConfirmTemplate MakeModifyOrderConfirmBtn(string message, int QIDnow, int OIDnow, string ShopID, string UserID)
        {
            var            actions            = new List <isRock.LineBot.TemplateActionBase>();
            NextHelper     nextHelper         = new NextHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailNext = nextHelper.GetNext();

            CancelHelper   cancelHelper         = new CancelHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailCancel = cancelHelper.GetCancel();
            string         confirmText          = GetConfirmText(QIDnow, OIDnow, ShopID);

            //OrderTmp orderTmp = new OrderTmp(UserID);
            //orderTmp.SelectByUserID();
            //string confirmText = $@"開始時間:{orderTmp.StartTime.ToString()}\結束時間:{orderTmp.EndTime.ToString()}";
            if (confirmText == "")
            {
                confirmText = message;
            }
            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "確定", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},{ShopID}"
            });
            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "取消", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
            });
            var ConfirmTemplateMsg = new isRock.LineBot.ConfirmTemplate()
            {
                altText = "替代文字(在無法顯示Confirm Template的時候顯示)",
                text    = confirmText,
                actions = actions //設定回覆動作
            };

            return(ConfirmTemplateMsg);
        }
예제 #7
0
        internal static ConfirmTemplate MakeCreateClubConfirmBtn(string message, int QIDnow, int OIDnow, string clubID, string clubName)
        {
            var actions = new List <isRock.LineBot.TemplateActionBase>();

            NextHelper     nextHelper         = new NextHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailNext = nextHelper.GetNext();

            CancelHelper   cancelHelper         = new CancelHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailCancel = cancelHelper.GetCancel();

            string confirmText = GetConfirmText(QIDnow, OIDnow, clubID);

            if (confirmText == "")
            {
                confirmText = message;
            }

            //參加社團(91)和退出社團(102)需要放clubID
            if (questionDetailNext.QID == 91 || questionDetailNext.QID == 102)
            {
                actions.Add(new isRock.LineBot.PostbackAction()
                {
                    label = "確定", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},{clubID}"
                });
            }
            else
            {
                actions.Add(new isRock.LineBot.PostbackAction()
                {
                    label = "確定", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},{clubName}"
                });
            }
            actions.Add(new isRock.LineBot.PostbackAction()
            {
                label = "取消", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
            });


            var ConfirmTemplateMsg = new isRock.LineBot.ConfirmTemplate()
            {
                altText = "替代文字(在無法顯示Confirm Template的時候顯示)",
                text    = confirmText,
                actions = actions //設定回覆動作
            };

            return(ConfirmTemplateMsg);
        }
예제 #8
0
        protected void Button4_Click(object sender, EventArgs e)
        {
            var bot     = new Bot(channelAccessToken);
            var actions = new List <isRock.LineBot.TemplateActionBase>();

            actions.Add(new isRock.LineBot.MessageActon()
            {
                label = "Yes", text = "Yes"
            });
            actions.Add(new isRock.LineBot.MessageActon()
            {
                label = "No", text = "No"
            });
            var ConfirmTemplate = new isRock.LineBot.ConfirmTemplate()
            {
                //title = "選項",
                text    = "請選其中之一",
                altText = "請在手機上觀看",
                //thumbnailImageUrl = new Uri("https://i.imgur.com/HF5tUXv.jpg"),
                actions = actions
            };

            bot.PushMessage(AdminUserId, ConfirmTemplate);
        }
예제 #9
0
        public IHttpActionResult POST()
        {
            try
            {
                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = channelAccessToken;
                //取得Line Event(範例,只取第一個)
                var LineEvent          = this.ReceivedMessage.events.FirstOrDefault();
                isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
                var UserInfo           = bot.GetUserInfo(LineEvent.source.userId);

                //配合Line verify
                //
                if (LineEvent.replyToken == "00000000000000000000000000000000")
                {
                    return(Ok());
                }
                if (LineEvent.type == "postback")
                {
                    var data = LineEvent.postback.data;
                    var dt   = LineEvent.postback.Params.time;
                    this.ReplyMessage(LineEvent.replyToken, $"觸發了 postback \n 資料為:{data}\n 選擇結果:{dt} ");
                }
                if (LineEvent.type == "message")
                {
                    //回覆訊息
                    //if (LineEvent.message.type == "sticker") //收到貼圖
                    //    this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    if (LineEvent.message.type == "location") //GPS
                    {
                        this.ReplyMessage(LineEvent.replyToken, $"你的位置在\n{LineEvent.message.latitude},{LineEvent.message.longitude}\n{LineEvent.message.address}");
                    }

                    if (LineEvent.message.type == "text")
                    {
                        if (LineEvent.message.text == "Hello")
                        {
                            this.ReplyMessage(LineEvent.replyToken, UserInfo.displayName + "您好,今天適合穿短袖上衣");
                        }
                    }

                    if (LineEvent.message.text == "餓了嗎")
                    {
                        var bott = new Bot(channelAccessToken);
                        //建立actions,作為ButtonTemplate的用戶回復行為
                        var actions = new List <isRock.LineBot.TemplateActionBase>();
                        actions.Add(new isRock.LineBot.MessageAction()
                        {
                            label = "Yes", text = "Yes"
                        });
                        actions.Add(new isRock.LineBot.MessageAction()
                        {
                            label = "No", text = "No"
                        });

                        var ConfirmTemplate = new isRock.LineBot.ConfirmTemplate()
                        {
                            text    = "請選擇其中之一",
                            altText = "請在手機上檢視",

                            actions = actions
                        };
                        bott.PushMessage(AdminUserId, ConfirmTemplate);
                    }
                    if (LineEvent.message.text == "Yes")
                    {
                        var bot1 = 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.UriAction()
                        {
                            label = "選擇餐廳", uri = new Uri("https://tgifridays.com.tw/locations")
                        });
                        // actions.Add(new isRock.LineBot.PostbackAction() { label = "標題-發生postback", data = "abc=aaa&def=111" });
                        actions.Add(new isRock.LineBot.DateTimePickerAction()
                        {
                            label = "請選擇時間", mode = "date"
                        });
                        var ButtonTemplateMsg = new isRock.LineBot.ButtonsTemplate()
                        {
                            title             = "選項",
                            text              = "請選擇其中之一",
                            altText           = "請在手機上檢視",
                            thumbnailImageUrl = new Uri("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQSfptbc-INs9IUyaBi7xU3_Hr52NbdIEOwOa_gX5xrrQXEd0m7w"),
                            actions           = actions
                        };
                        bot1.PushMessage(AdminUserId, ButtonTemplateMsg);
                    }
                    if (LineEvent.message.type == "image")
                    {
                        //取得圖片Bytes
                        var bytes = this.GetUserUploadedContent(LineEvent.message.id);
                        //儲存為圖檔
                        var guid     = Guid.NewGuid().ToString();
                        var filename = $"{guid}.png";
                        var path     = System.Web.Hosting.HostingEnvironment.MapPath("~/Temps/");

                        System.IO.File.WriteAllBytes(path + filename, bytes);

                        //取得base URL
                        var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority);
                        //組出外部可以讀取的檔名
                        var url = $"{baseUrl}/Temps/{filename}";
                        // this.ReplyMessage(LineEvent.replyToken, $"你的圖片位於\n{url}");
                        var fs1 = new FileStream(path + filename, FileMode.Open);
                        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fs1);
                        Graphics g = Graphics.FromImage(bmp);
                        fs1.Close();

                        var visionClient = new Microsoft.ProjectOxford.Vision.VisionServiceClient(VisionAPIKey,
                                                                                                  "https://southeastasia.api.cognitive.microsoft.com/vision/v1.0");

                        //分析圖片(從FileUpload1.PostedFile.InputStream取得影像)
                        //分析 Faces & Description

                        var Results = visionClient.AnalyzeImageAsync(url,
                                                                     new VisualFeature[] { VisualFeature.Faces, VisualFeature.Description }).Result;

                        int isM = 0, isF = 0;
                        foreach (var Face in Results.Faces)
                        {
                            //取得人臉位置
                            var faceRect = Face.FaceRectangle;
                            //繪製人臉紅框
                            g.DrawRectangle(
                                new Pen(Brushes.Red, 10),
                                new Rectangle(faceRect.Left, faceRect.Top,
                                              faceRect.Width, faceRect.Height));

                            Font       drawFont   = new Font("Arial", 40);
                            SolidBrush drawBrush  = new SolidBrush(Color.Red);
                            String     drawString = Face.Age.ToString();

                            g.DrawString(drawString + "歲", drawFont, drawBrush, new Point(faceRect.Left - 30, faceRect.Top - 50));

                            //計算幾男幾女
                            if (Face.Gender.StartsWith("M"))
                            {
                                isM += 1;
                            }
                            else
                            {
                                isF += 1;
                            }
                        }
                        var path1       = System.Web.Hosting.HostingEnvironment.MapPath("~/Temps/");
                        var newfilename = Guid.NewGuid().ToString() + ".png";
                        bmp.Save(path1 + newfilename);

                        this.ReplyMessage(LineEvent.replyToken, new Uri($"{baseUrl}/Temps/{newfilename}"));
                    }
                }

                return(Ok());

                //this.ReplyMessage(LineEvent.replyToken, "Hello,你的UserId是:" + LineEvent.source.userId);
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
예제 #10
0
        public IHttpActionResult POST()
        {
            //設定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 == "message")
            {
                this.AdminUserId = this.ReceivedMessage.events.FirstOrDefault().source.userId; //取得用戶資訊
                //string EmpId = "MSIT1230015";//測試用用戶
                string      st1    = "10:00";                                                  //設定最晚打卡的上班時間
                DateTime    dt1    = Convert.ToDateTime(st1);
                DateTime    todate = DateTime.Now.Date;                                        //今天的日期
                Entities    d      = new Entities();
                Attendances a      = new Attendances();
                if (LineEvent.message.type == "text")
                {
                    if (LineEvent.message.text == "打卡")
                    {
                        var bot = new Bot(channelAccessToken);
                        List <TemplateActionBase> actions = new List <TemplateActionBase>();
                        actions.Add(new MessageAction()
                        {
                            label = "上班", text = "上班"
                        });
                        actions.Add(new MessageAction()
                        {
                            label = "下班", text = "下班"
                        });

                        var ButtonTempalteMsg = new isRock.LineBot.ConfirmTemplate()
                        {
                            text    = "打卡",
                            altText = "請在手機上檢視",
                            actions = actions
                        };
                        bot.PushMessage(AdminUserId, ButtonTempalteMsg);
                    }


                    switch (LineEvent.message.text)
                    {
                    case "上班":
                        if (DateTime.Now < dt1)
                        {
                            a.LineID = AdminUserId;
                            a.Date   = todate;
                            a.Onduty = DateTime.Now;
                            d.Attendances.Add(a);
                            try
                            {
                                d.SaveChanges();
                                this.ReplyMessage(LineEvent.replyToken, $"已打卡\n時間:{DateTime.Now.ToString()}");
                            }
                            catch
                            {
                                var query = d.Attendances.Where(p => p.LineID == AdminUserId && p.Date == todate && p.Onduty != null).First();
                                this.ReplyMessage(LineEvent.replyToken, "已經在" + $"{query.Onduty}打過卡了");
                            }


                            return(Ok());
                        }
                        else
                        {
                            this.ReplyMessage(LineEvent.replyToken, "已超過可打卡的時間");
                        }
                        break;

                    case "下班":
                        try
                        {
                            var query = d.Attendances.Where(p => p.LineID == AdminUserId && p.Date == todate && p.Onduty != null).First();
                            query.Offduty = DateTime.Now;

                            this.ReplyMessage(LineEvent.replyToken, $"已打卡\n時間:{DateTime.Now.ToString()}");

                            d.SaveChanges();
                        }

                        catch
                        {
                            this.ReplyMessage(LineEvent.replyToken, "小幫手提醒您,今天上班未打卡,請申請補打卡!");
                        }

                        break;
                    }
                }
            }
            //response OK
            return(Ok());

            //catch (Exception ex)
            //{
            //    //如果發生錯誤,傳訊息給Admin
            //    this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
            //    //response OK
            //    return Ok();
            //}
        }
예제 #11
0
        internal static ConfirmTemplate MakeContinueConfirmBtn(string message, int QIDnow, int OIDnow)
        {
            var            actions            = new List <isRock.LineBot.TemplateActionBase>();
            NextHelper     nextHelper         = new NextHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailNext = nextHelper.GetNext();

            CancelHelper   cancelHelper         = new CancelHelper(QIDnow, OIDnow);
            QuestionDetail questionDetailCancel = cancelHelper.GetCancel();

            string confirmText = "";

            confirmText = GetConfirmText(QIDnow, OIDnow, "");

            if (confirmText == "")
            {
                confirmText = message;
            }
            switch (QIDnow)
            {
            case 121:
                switch (OIDnow)
                {
                case 5:
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "繼續修改", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
                    });
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "結束修改", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
                    });
                    break;

                default:
                    break;
                }
                break;

            case 194:
                switch (OIDnow)
                {
                case 5:
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "繼續修改", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
                    });
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "結束修改", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
                    });
                    break;

                default:
                    break;
                }
                break;

            case 211:
                switch (OIDnow)
                {
                case 3:
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "繼續選擇", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
                    });
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "結束選擇", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
                    });
                    break;

                default:
                    break;
                }
                break;

            case 251:
                switch (OIDnow)
                {
                case 3:
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "繼續選擇", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
                    });
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "結束選擇", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
                    });
                    break;

                default:
                    break;
                }
                break;

            case 294:
                switch (OIDnow)
                {
                case 5:
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "繼續修改", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
                    });
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "結束修改", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
                    });
                    break;

                default:
                    break;
                }
                break;

            case 9999:
                switch (OIDnow)
                {
                case 5:
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "繼續訂購", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
                    });
                    actions.Add(new isRock.LineBot.PostbackAction()
                    {
                        label = "結束訂購", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
                    });
                    break;

                default:
                    break;
                }
                break;

            default:
                actions.Add(new isRock.LineBot.PostbackAction()
                {
                    label = "繼續輸入", data = $"{DateTime.Now},{questionDetailNext.QID},{questionDetailNext.OID},"
                });
                actions.Add(new isRock.LineBot.PostbackAction()
                {
                    label = "結束輸入", data = $"{DateTime.Now},{questionDetailCancel.QID},{questionDetailCancel.OID},"
                });
                break;
            }


            var ConfirmTemplateMsg = new isRock.LineBot.ConfirmTemplate()
            {
                altText = "替代文字(在無法顯示Confirm Template的時候顯示)",
                text    = confirmText,
                actions = actions //設定回覆動作
            };

            return(ConfirmTemplateMsg);
        }