//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);
        }
Example #2
0
 public BotService(string token, string admin, Event evt)
 {
     AdminId            = admin;
     ChannelAccessToken = token;
     _RockBot           = new Bot(ChannelAccessToken);
     _Event             = evt;
 }
        //ButtonsTemplate
        protected void Button1_Click(object sender, EventArgs e)
        {
            var bot = new isRock.LineBot.Bot(channelAccessToken);

            var ButtonTmpMsg = new isRock.LineBot.ButtonsTemplate()
            {
                text              = "文字",
                title             = "標題",
                altText           = "替代文字",
                thumbnailImageUrl = new Uri("https://66.media.tumblr.com/2e37eafc9b6b715ed99b31fb6f72e6a5/tumblr_inline_pjjzfnFy7a1u06gc8_640.jpg")
            };
            //add actions
            var action1 = new isRock.LineBot.MessageAction()
            {
                label = "顯示的標題", text = "呈現的文字"
            };

            ButtonTmpMsg.actions.Add(action1);

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

            ButtonTmpMsg.actions.Add(action2);

            bot.PushMessage(AdminUserId, ButtonTmpMsg);
        }
Example #4
0
        protected void Button6_Click(object sender, EventArgs e)
        {
            isRock.LineBot.Bot bot = new isRock.LineBot.Bot("9YwfPyWbdWkYqcs5aistrwDTZaPwLAivy+9vpvKS034TVyF9Cj7UhHcttzo4CJ1+zLH7YadJ7B5U9a9ho/4Kg6mU+Z5u0bHvo8zo7y3+8BwccBpL+4QDGrknX16T3roNmLnxVaOhmwkyXXQ/G2INFwdB04t89/1O/w1cDnyilFU=");
            var Userinfo           = bot.GetUserInfo("U275c68b802e11bb599413ef87dcea051");

            Response.Write(Userinfo.displayName + "<br/>" + Userinfo.pictureUrl + "<br/>" + Userinfo.statusMessage);
        }
        public IActionResult LineBotTest()
        {
            try
            {
                var bot = new isRock.LineBot.Bot(ChannelAccessToken);
                //push text
                bot.PushMessage(_UserID, "Hello World");

            }
            catch (Exception ex)
            {

            }
            return Ok();
        }
Example #6
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
            //建立buttonsTemplate
            var button = new isRock.LineBot.ButtonsTemplate()
            {
                altText           = "altText",
                text              = "text",
                title             = "title",
                thumbnailImageUrl = new Uri("https://i.imgur.com/pAiJpHg.png")
            };

            //actions
            button.actions.Add(new isRock.LineBot.MessageAction()
            {
                label = "美式漢堡",
                text  = "美式漢堡"
            });
            button.actions.Add(new isRock.LineBot.MessageAction()
            {
                label = "台灣漢堡",
                text  = "台灣漢堡"
            });
            button.actions.Add(new isRock.LineBot.MessageAction()
            {
                label = "熱狗堡",
                text  = "熱狗堡"
            });

            //建立訊息集合(一次發送多則訊息)
            var msgs = new List <isRock.LineBot.MessageBase>();

            //add messages to
            msgs.Add(new isRock.LineBot.TextMessage("請選擇您喜歡的餐點:"));
            var ButtonsTmp = new isRock.LineBot.TemplateMessage(button);

            //quickReply
            ButtonsTmp.quickReply.items.Add(
                new isRock.LineBot.QuickReplyDatetimePickerAction(
                    "期望送達時間", "期望送達時間", isRock.LineBot.DatetimePickerModes.time));
            //將ButtonsTmp加入msgs
            msgs.Add(ButtonsTmp);
            //發送
            bot.PushMessage(AdminUserId, msgs);
        }
        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);
        }
Example #8
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Bot bot     = new isRock.LineBot.Bot("WJ10DIkt+Y8abCGbAb/OmK/35F3iZ3h4xiB3CE8/B6SzkfTg4mLGonn/9nVI/P33o6+SnGwSBtKYjfa65YJSdfskV7Lf5RtWUAEmZajgARKdJva3ufd3cn7i/H4F/FXA685e75j18IsFjwDgSmugcQdB04t89/1O/w1cDnyilFU=");
            var actions = new List <TemplateActionBase>();

            actions.Add(new DateTimePickerAction()
            {
                label = "選取時間",
                mode  = "time"
            });
            var ButtonTemplate = new ButtonsTemplate()
            {
                text              = "選取時間來設定自動推送訊息喔~~",
                title             = "設定推送任務時間",
                thumbnailImageUrl = new Uri("http://www.sayjb.com/wp-content/uploads/2017/02/unnamed-file-9.jpg"),
                actions           = actions
            };

            bot.PushMessage("Ub7f9aa656d9493aa12bc911993678a4e", ButtonTemplate);
        }
        //QuickReplyMessageAction
        protected void Button3_Click(object sender, EventArgs e)
        {
            //icon位置
            const string IconUrl = "https://pic.pimg.tw/chico386/1414112596-3072196168_n.png";

            //建立一個TextMessage物件
            isRock.LineBot.TextMessage m =
                new isRock.LineBot.TextMessage("請在底下選擇一個選項");

            //在TextMessage物件的quickReply屬性中加入items
            m.quickReply.items.Add(
                new isRock.LineBot.QuickReplyMessageAction(
                    $"一般標籤", "點選後顯示的text文字"));

            m.quickReply.items.Add(
                new isRock.LineBot.QuickReplyMessageAction(
                    $"有圖示的標籤", "點選後顯示的text文字", new Uri(IconUrl)));
            //加入QuickReplyDatetimePickerAction
            m.quickReply.items.Add(
                new isRock.LineBot.QuickReplyDatetimePickerAction(
                    "選時間", "選時間", isRock.LineBot.DatetimePickerModes.datetime,
                    new Uri(IconUrl)));
            //加入QuickReplyLocationAction
            m.quickReply.items.Add(
                new isRock.LineBot.QuickReplyLocationAction(
                    "選地點", new Uri(IconUrl)));
            //加入QuickReplyCameraAction
            m.quickReply.items.Add(
                new isRock.LineBot.QuickReplyCameraAction(
                    "Show Camera", new Uri(IconUrl)));
            //加入QuickReplyCamerarollAction
            m.quickReply.items.Add(
                new isRock.LineBot.QuickReplyCamerarollAction(
                    "Show Cameraroll", new Uri(IconUrl)));
            //建立bot instance
            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(channelAccessToken);
            //透過Push發送訊息
            bot.PushMessage(AdminUserId, m);
        }
Example #10
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());
            }
        }
        public IHttpActionResult POST()
        {
            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 == "message")
                {
                    isRock.LineBot.Bot bot = new isRock.LineBot.Bot(ChannelAccessToken);
                    var userinfo           = bot.GetUserInfo(LineEvent.source.userId);
                    if (LineEvent.message.type == "text") //收到文字
                    {
                        switch (LineEvent.message.text)
                        {
                        case "/上一頁":
                            SwitchMenuTo("快捷選單1", LineEvent);
                            break;

                        case "/下一頁":
                            SwitchMenuTo("快捷選單2", LineEvent);
                            break;

                        case "秘書告退":
                            if (LineEvent.source.type.ToLower() == "room")
                            {
                                Utility.LeaveRoom(LineEvent.source.roomId, channelAccessToken);
                            }
                            else if (LineEvent.source.type.ToLower() == "group")
                            {
                                Utility.LeaveRoom(LineEvent.source.groupId, channelAccessToken);
                            }
                            else
                            {
                                this.ReplyMessage(LineEvent.replyToken, "你開玩笑嗎?");
                            }
                            break;

                        default:
                            Models.blah rec = new Models.blah();
                            rec.userId      = LineEvent.source.userId;
                            rec.displayName = userinfo.displayName;
                            rec.message     = LineEvent.message.text;
                            rec.createdDate = DateTime.Now;

                            Models.MainDBDataContext db = new Models.MainDBDataContext();
                            db.blah.InsertOnSubmit(rec);
                            db.SubmitChanges();

                            this.ReplyMessage(LineEvent.replyToken, "Hi," + userinfo.displayName + "(" + LineEvent.source.userId + "), 你說了:"
                                              + LineEvent.message.text + "(" + DateTime.Now.ToString() + ")");
                            break;
                        }
                    }
                    if (LineEvent.message.type == "sticker") //收到貼圖
                    {
                        this.ReplyMessage(LineEvent.replyToken, 1, 2);
                    }
                }
                //回覆訊息
                if (LineEvent.type == "image")
                {
                    string path     = System.Web.HttpContext.Current.Request.MapPath("/temp/");
                    string filename = Guid.NewGuid().ToString() + ".png";
                    var    filebody = this.GetUserUploadedContent(LineEvent.message.id);
                    System.IO.File.WriteAllBytes(path + filename, filebody);
                }
                //檢查用戶如果當前沒有任何選單,則嘗試綁定快捷選單1
                var currentMenu = isRock.LineBot.Utility.GetRichMenuIdOfUser(LineEvent.source.userId, channelAccessToken);
                if (currentMenu == null || string.IsNullOrEmpty(currentMenu.richMenuId))
                {
                    SwitchMenuTo("快捷選單1", LineEvent);
                }
                if (isRock.LineBot.Utility.GetRichMenu(currentMenu.richMenuId, channelAccessToken) == null)
                {
                    SwitchMenuTo("快捷選單1", LineEvent);
                }
                //response OK
                return(Ok());
            }
            catch (Exception ex)
            {
                //如果發生錯誤,傳訊息給Admin
                this.PushMessage(AdminUserId, "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
        public IHttpActionResult POST()
        {
            string ChannelAccessToken = "iNNBsIPiNof4jbpItGP+ypxTkKManP+E3hnBxXwi19ocbv3hc0SkKwo0AzBof1FIGtfwU2JhwlKliADbZ7R0zeCOPj2FNCnXpEjh41fDanX+1d59gZEOhMPF+AIiOfe3J1R+n/viuS50u3/iFocdhwdB04t89/1O/w1cDnyilFU=";

            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(ChannelAccessToken);
            //取得 http Post RawData(should be JSON)
            string postData        = Request.Content.ReadAsStringAsync( ).Result;
            var    ReceivedMessage = isRock.LineBot.Utility.Parsing(postData);



            var item = ReceivedMessage.events[0];

            //var userinfo = isRock.LineBot.Utility.GetUserInfo ( ReceivedMessage.events[0].source.userId, ChannelAccessToken );
            //var userInfo = bot.GetUserInfo ( ReceivedMessage.events.FirstOrDefault ( ).source.userId );

            //var userInfo = bot.GetUserInfo ( ReceivedMessage.events.FirstOrDefault ( ).source.userId );

            //var UserSays = ReceivedMessage.events[0].message.text;
            var ReplyToken = ReceivedMessage.events[0].replyToken;
            //string Message = "";
            bool Trigger = false;

            //String CurrMsg = ReceivedMessage.events[0].message.text.Substring ( 4 ).ToString ( );

            if (ReceivedMessage.events[0].message.type.ToLower( ) == "sticker")
            {
                bot.ReplyMessage(ReceivedMessage.events[0].replyToken, " 我的主人還沒教我怎麼使用貼圖!><'''");
                return(Ok( ));
            }
            else
            {
                try
                {
                    UserID = ReceivedMessage.events[0].source.userId;
                    string RoomID = "";
                    if (item.source.type.ToLower( ) == "room")
                    {
                        RoomID = item.source.roomId;
                    }
                    else if (item.source.type.ToLower( ) == "group")
                    {
                        RoomID = item.source.groupId;
                    }
                    else
                    {
                    }
                    AddMsg(UserID, RoomID, ReceivedMessage.events[0].message.text);
                }
                catch (Exception ex)
                {
                    bot.ReplyMessage(ReceivedMessage.events[0].replyToken, "add ERR:" + ex.ToString( ));
                }

                Message = REPLAYMSG(ReceivedMessage.events[0].message.text);
                if (Message == "")
                {
                    if (ReceivedMessage.events[0].message.text.Length <15 && ReceivedMessage.events[0].message.text.ToLower( ).IndexOf("google", 0)> -1)
                    {
                        string searchStr = "";
                        searchStr = ReceivedMessage.events[0].message.text;
                        searchStr = searchStr.Replace("GOOGLE", "");
                        searchStr = searchStr.Replace("google", "");
                        searchStr = searchStr.Replace(" ", "");

                        Message = "google大神是你的好朋友" + "\n" + "https://www.google.com/search?q=" + searchStr;
                        Trigger = true;
                    }
                    else
                    {
                        //Message = "啦啦啦,不想理你!";
                        //Trigger = true;
                    }
                }
                else
                {
                    Trigger = true;
                }

                try
                {
                    if (Trigger)
                    {
                        bot.ReplyMessage(ReceivedMessage.events[0].replyToken, Message);
                    }

                    return(Ok( ));
                }

                catch (Exception ex)
                {
                    //bot.ReplyMessage ( ReceivedMessage.events[0].replyToken, "POST ERR:" + ex.ToString ( ) );
                    return(Ok( ));
                }
            }
        }
        public static void Handle(int _subState, ReceievedMessage _ReceivedMessage)
        {
            var _LineEvent   = _ReceivedMessage.events.FirstOrDefault();
            var _userId      = _LineEvent.source.userId;
            var ChannelToken = ConfigurationManager.AppSettings["ChannelAccessToken"];

            isRock.LineBot.Bot bot = new isRock.LineBot.Bot(ChannelToken);
            var userInfo           = bot.GetUserInfo(_userId);

            switch (_subState)
            {
            case (int)SubStateEnum.Step0:

                if (!Process_Validate.Handle(_LineEvent, bot))
                {
                    return;
                }

                bot.ReplyMessage(_LineEvent.replyToken, $"哈,'{userInfo.displayName}' 你來了...歡迎,現在開始用藥流程對話");
                azQuery.resetStatus(string.Concat(0, (int)StateEnum.DrugRemind, 0, (int)SubStateEnum.Step1));

                break;

            case (int)SubStateEnum.Step1:

                if (!Process_Validate.Handle(_LineEvent, bot))
                {
                    return;
                }

                bot.ReplyMessage(_LineEvent.replyToken, $"哈,'{userInfo.displayName}' 現在是第一階段對話");
                azQuery.resetStatus(string.Concat(0, (int)StateEnum.DrugRemind, 0, (int)SubStateEnum.Step2));

                break;

            case (int)SubStateEnum.Step2:

                if (!Process_Validate.Handle(_LineEvent, bot))
                {
                    return;
                }

                bot.ReplyMessage(_LineEvent.replyToken, $"哈,'{userInfo.displayName}' 現在是第二階段對話");
                azQuery.resetStatus(string.Concat(0, (int)StateEnum.DrugRemind, 0, (int)SubStateEnum.Step3));

                break;

            case (int)SubStateEnum.Step3:

                if (!Process_Validate.Handle(_LineEvent, bot))
                {
                    return;
                }

                bot.ReplyMessage(_LineEvent.replyToken, $"哈囉,'{userInfo.displayName}' 現在是最後階段對話");
                azQuery.resetStatus(string.Concat(0, (int)StateEnum.DrugRemind, 0, (int)SubStateEnum.StepReset));

                break;

            case (int)SubStateEnum.Step4:


                break;

            case (int)SubStateEnum.Step5:

                break;

            case (int)SubStateEnum.Step6:

                break;

            default:
                break;
            }
        }
Example #14
0
        public IHttpActionResult POST()
        {
            //設定你的Channel Access Token
            string ChannelAccessToken = "FRIVkZ1ddfC90UObByPBHb/RfaotMELEVzQ4YPlKJOzSPrDCJ2uzeewA1mVaSX7+e3Qip3deQ5xjpHU9ut8v+HRpt4xwmxefP8O8GlUb8ynT7v6gmErTDz5+Xl1kyI1+YGpu3DdE24G1oQ/om/gi3QdB04t89/1O/w1cDnyilFU=";

            isRock.LineBot.Bot bot;
            //如果有Web.Config app setting,以此優先
            if (System.Configuration.ConfigurationManager.AppSettings.AllKeys.Contains("LineChannelAccessToken"))
            {
                ChannelAccessToken = System.Configuration.ConfigurationManager.AppSettings["LineChannelAccessToken"];
            }

            //create bot instance
            bot = new isRock.LineBot.Bot(ChannelAccessToken);

            try
            {
                //取得 http Post RawData(should be JSON)
                string postData = Request.Content.ReadAsStringAsync().Result;
                //剖析JSON
                var ReceivedMessage = isRock.LineBot.Utility.Parsing(postData);
                var UserSays        = ReceivedMessage.events[0].message.text;
                var ReplyToken      = ReceivedMessage.events[0].replyToken;

                string      Message     = "";
                MysqlLineID mysqlLineID = new MysqlLineID();
                var         item        = ReceivedMessage.events.FirstOrDefault();
                //依照用戶說的特定關鍵字來回應
                switch (UserSays.ToLower())
                {
                case "/teststicker":
                    //回覆貼圖
                    bot.ReplyMessage(ReplyToken, 1, 1);
                    break;

                case "/testimage":
                    //回覆圖片
                    bot.ReplyMessage(ReplyToken, new Uri("https://scontent-tpe1-1.xx.fbcdn.net/v/t31.0-8/15800635_1324407647598805_917901174271992826_o.jpg?oh=2fe14b080454b33be59cdfea8245406d&oe=591D5C94"));
                    break;

                case "b":

                    if (mysqlLineID.DBConnectionInsert(@"INSERT INTO `linemessage`(`Msg`, `ID`) VALUES ('" + UserSays + "','" + ReceivedMessage.events[0].source.userId + "');") == "true")
                    {
                        Message += "預約成功,您預約資料為:" + UserSays;
                    }
                    else
                    {
                        Message += "輸入錯誤!!,請重新輸入!!";
                    }
                    bot.ReplyMessage(ReplyToken, Message + "!");
                    break;

                default:
                    //回覆訊息
                    Message += "哈囉, 歡迎您加入,預約請輸入 b :";     //+ UserSays; //+"ID:"+ReceivedMessage.events[0].source.userId;
                                                          //測試方法: 紀錄
                    if (!mysqlLineID.DBConnectionjudge("lineid", ReceivedMessage.events[0].source.userId))
                    {
                        Message += mysqlLineID.DBConnectionInsert(@"INSERT INTO `lineid`(`Name`, `ID`) VALUES ('Test','" + ReceivedMessage.events[0].source.userId + "');");
                        //Message += mysqlLineID.DBConnectionInsert(@"INSERT INTO `linemessage`(`Msg`, `ID`) VALUES ('" + UserSays + "','" + ReceivedMessage.events[0].source.userId + "');");
                    }


                    //回覆用戶
                    bot.ReplyMessage(ReplyToken, Message + "!");

                    break;
                }
                //回覆API OK
                return(Ok());
            }
            catch (Exception ex)
            {
                return(Ok());
            }
        }