예제 #1
0
        private isRock.LineBot.MessageBase ProcessCommand(Event LineEvent)
        {
            var language        = LineEvent.message.text.Trim().Replace("/翻成", "");
            var SupportLanguage = MyFun.Languagelist();
            var ret             = from c in SupportLanguage
                                  where c.Key == language
                                  select c;

            if (ret.Count() > 0)
            {
                SetState(LineEvent.source.userId, ret.FirstOrDefault().Value);
                var ResponseMsg = new isRock.LineBot.TextMessage($"好的,後面你輸入的句子我會開始翻譯成{ret.FirstOrDefault().Key},如要停止翻譯 /停止翻譯");
                return(ResponseMsg);
            }
            else
            {
                var ResponseMsg = new isRock.LineBot.TextMessage($"喔喔,我還認不得你要的語言 - {language}");
                return(ResponseMsg);
            }
        }
예제 #2
0
        /// <summary>
        /// (-)  查詢訂單動作
        /// </summary>
        /// <param name="service"></param>
        /// <param name="textMsg"></param>
        private void SelectOrder()
        {
            _Statue = "SelectOrder";

            if (_LineEvent.type == "message")
            {
                ///查詢訂單動作
                _TextMessage = new TextMessage("請問您要查詢哪天訂單?");
                _TextMessage.quickReply.items.Add(new QuickReplyDatetimePickerAction("選取查詢日期", "data", DatetimePickerModes.date));
            }
            else if (_LineEvent.type == "postback")
            {
                ///選擇日期完動作
                OrderService service = new OrderService(_LineEvent.source.userId);
                var          orders  = service.GetAllOrderByDate(_LineEvent.postback.Params.date);///格式 yyyy-MM-dd

                //_ReplyMessage = orders?.Any() == true ? $"{string.Join("\r\n\r\n", orders.Select(t => $" 哪一餐:{t.type}\r\n 餐廳:{t.restaurant}\r\n 餐點內容:{t.meal}\r\n 訂購時間:{t.orderTime}"))}"
                //                                                               : $"{_LineEvent.postback.Params.date} 查無點餐紀錄";
                _Statue = string.Empty;
            }
        }
예제 #3
0
        //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);
        }
예제 #4
0
        /// <summary>
        /// (-)  點菜單動作
        /// </summary>
        private void OrderMeal()
        {
            _Statue = "OrderMeal";

            //定義接收CIC結果的類別
            ProcessResult <Models.LineConversation.Order_C.Order_Request> result;
            OrderService service = new OrderService(_LineEvent.source.userId);

            var CIC = service.GetConversationCIC(_ChannelAccessToken);

            if (_LineEvent.message.text == "OrderMeal")
            {
                ///開始點餐程序

                //把訊息丟給CIC
                result = CIC.Process(_SendData.events.FirstOrDefault(), true);
            }
            else
            {
                //把訊息丟給CIC
                result = CIC.Process(_LineEvent);
            }

            //isRock.LineBot.TextMessage textMsg = new isRock.LineBot.TextMessage(result.ResponseMessageCandidate);

            _TextMessage = new isRock.LineBot.TextMessage(result.ResponseMessageCandidate);;

            //處理 CIC回覆的結果
            switch (result.ProcessResultStatus)
            {
            case ProcessResultStatus.Processed:
                ///繼續對話

                service.QuickReply_Order(_TextMessage);
                //_Bot.PushMessage(_LineEvent.source.userId, _TextMessage);
                return;

            case ProcessResultStatus.Done:
                ///完成對話
                service.AddOrder(Newtonsoft.Json.JsonConvert.SerializeObject(result.ConversationState.ConversationEntity));

                _ReplyMessage = "完成訂單!!";
                _Statue       = string.Empty;
                return;

            case ProcessResultStatus.Pass:
                ///目前不再對話狀態中,非典餐過程
                _Statue = string.Empty;
                break;

            case ProcessResultStatus.Exception:
                ///取得候選訊息發送,例外
                _ReplyMessage += result.ResponseMessageCandidate;
                break;

            case ProcessResultStatus.Break:
                ///離開對話
                ///responseMsg += result.ResponseMessageCandidate;
                _ReplyMessage = "中止點餐";
                _Statue       = string.Empty;
                return;

            case ProcessResultStatus.InputDataFitError:
                ///內容轉型失敗

                ///可以判斷狀態再重新計一次QuickReply
                service.QuickReply_Order(_TextMessage);
                return;

            default:
                //取得候選訊息發送
                _ReplyMessage += result.ResponseMessageCandidate;
                break;
            }
        }
예제 #5
0
        public IHttpActionResult webhook()
        {
            string ChannelAccessToken = "pm8zf310EYYHjvJEkM347wenUZDiP8IBf/lMfqeoBIroaBQkcyNcg2Me+dQR1lmVDRBPatCB0MjIanxkFa8taRPYX9g+GcmeEuWfz2hf8Gx4SZcxRiYMLcjFVmpw3GhkejYKTkJX/uqjQoDndGNo9wdB04t89/1O/w1cDnyilFU=";

            try
            {
                this.ChannelAccessToken = ChannelAccessToken;
                string Message = "";
                var    item    = this.ReceivedMessage.events.FirstOrDefault();
                isRock.LineBot.Event LineEvent = null;

                LineUserInfo UserInfo = null;
                if (item.source.type.ToLower() == "room")
                {
                    UserInfo = Utility.GetRoomMemberProfile(
                        item.source.roomId, item.source.userId, ChannelAccessToken);
                }
                if (item.source.type.ToLower() == "group")
                {
                    UserInfo = Utility.GetGroupMemberProfile(
                        item.source.groupId, item.source.userId, ChannelAccessToken);
                }
                if (item.source.type.ToLower() == "user")
                {
                    UserInfo = Utility.GetUserInfo(item.source.userId, ChannelAccessToken);
                }

                if (item != null)
                {
                    switch (item.type)
                    {
                    case "join":
                        //Message = $"有人把我加入{item.source.type}中了,大家好啊~";
                        Message = $"初次見面多多指教,大家好ㄛ~";
                        //回覆用戶
                        Utility.ReplyMessage(ReceivedMessage.events[0].replyToken, Message, ChannelAccessToken);
                        break;

                    case "message":
                        int question_id = service.HaveQuestion(item.source.userId);
                        if (question_id != 0)
                        {
                            MessageAction[] actions  = null;
                            var             msgArray = service.NextQuestion(item.source.userId, ReceivedMessage.events[0].message.text).Split(',');
                            isRock.LineBot.ButtonsTemplate ButtonTemplate = null;
                            switch (msgArray[1])
                            {
                            case "1":
                                actions = new MessageAction[]
                                {
                                    new MessageAction {
                                        label = "威秀影城", text = "威秀"
                                    },
                                    new MessageAction {
                                        label = "國賓影城", text = "國賓"
                                    }
                                };
                                ButtonTemplate = GetButtonsTemplate(msgArray[0], msgArray[0], $"請選擇要查詢之戲院", actions);
                                Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken);
                                break;

                            case "2":
                                if (msgArray[2] == "VS")
                                {
                                    actions = new MessageAction[]
                                    {
                                        new MessageAction {
                                            label = "京站威秀", text = "京站"
                                        },
                                        new MessageAction {
                                            label = "信義威秀", text = "信義"
                                        },
                                        new MessageAction {
                                            label = "日新威秀", text = "日新"
                                        },
                                        new MessageAction {
                                            label = "板橋大遠百威秀", text = "板橋大遠百"
                                        }
                                    };
                                    ButtonTemplate = GetButtonsTemplate(msgArray[0], "請點選下方戲院", msgArray[0], actions);
                                    Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken);
                                }
                                else if (msgArray[2] == "AT")
                                {
                                    actions = new MessageAction[]
                                    {
                                        new MessageAction {
                                            label = "西門國賓", text = "西門國賓"
                                        },
                                        new MessageAction {
                                            label = "威風國賓", text = "威風國賓"
                                        },
                                        new MessageAction {
                                            label = "長春國賓", text = "長春國賓"
                                        },
                                        new MessageAction {
                                            label = "中和環球國賓", text = "中和環球國賓"
                                        }
                                    };
                                    ButtonTemplate = GetButtonsTemplate(msgArray[0], "請點選下方戲院地點(林口國賓、新莊國賓請直接輸入)", msgArray[0], actions);
                                    Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken);
                                }
                                break;

                            default:
                                Utility.ReplyMessage(item.replyToken, msgArray[0], ChannelAccessToken);
                                break;
                            }
                        }

                        if (item.message.type.ToLower() == "image")
                        {
                            if (imageService.isUploading(item.source.userId))
                            {
                                var byteArray = Utility.GetUserUploadedContent(item.message.id, ChannelAccessToken);
                                var link      = imageService.UploadImage(byteArray, item.source.userId, UserInfo.displayName);
                                isRock.LineBot.TextMessage  textMessage  = new isRock.LineBot.TextMessage("---Completed!---");
                                isRock.LineBot.ImageMessage imageMessage = new isRock.LineBot.ImageMessage(new Uri(link), new Uri(link));
                                var Messages = new List <MessageBase>();
                                Messages.Add(textMessage);
                                Messages.Add(imageMessage);
                                this.ReplyMessage(item.replyToken, Messages);
                            }
                        }
                        else if (item.message.type.ToLower() == "text")
                        {
                            switch (ReceivedMessage.events[0].message.text)
                            {
                            case "--exit":
                                Utility.ReplyMessage(item.replyToken, "bye-bye", ChannelAccessToken);

                                //離開
                                if (item.source.type.ToLower() == "room")
                                {
                                    Utility.LeaveRoom(item.source.roomId, ChannelAccessToken);
                                }
                                else if (item.source.type.ToLower() == "group")
                                {
                                    Utility.LeaveGroup(item.source.groupId, ChannelAccessToken);
                                }

                                break;

                            case "--upload":
                                var msg = imageService.addUploadStatus(item.source.userId);
                                if (!string.IsNullOrEmpty(msg))
                                {
                                    Message = msg;
                                    if (UserInfo != null)
                                    {
                                        Message += $"\r\n -Target user: \"{UserInfo.displayName}\"";
                                    }
                                    this.ReplyMessage(item.replyToken, Message);
                                }
                                else
                                {
                                    Message = "Plz try again. :(";
                                }
                                break;

                            case string str when str.Contains("抽老公") || str.Contains("抽帥哥"):
                                string _url = service.GetRandomGuy();

                                if (!string.IsNullOrEmpty(_url))
                                {
                                    isRock.LineBot.ImageMessage imageMessage = new isRock.LineBot.ImageMessage(new Uri(_url), new Uri(_url));
                                    var Messages = new List <MessageBase>();
                                    Messages.Add(imageMessage);
                                    this.ReplyMessage(item.replyToken, Messages);
                                }
                                else
                                {
                                    this.ReplyMessage(item.replyToken, "你沒帥哥或是正在維修中..請洽詢我老闆 :D");
                                }
                                break;

                            case "-help":
                                Message = "抽帥哥圖片(指令:抽帥哥/抽老公)\r\n========\r\n抽動物圖片(指令:抽動物)\r\n========\r\n查詢地方當前溫度(指令:xx氣溫 / xx溫度)\r\n========\r\n查詢星座今日運勢 (指令:xx座運勢)\r\n========\r\n" +
                                          "查詢電影(指令:查詢電影)如果要中斷請輸入\"取消\"\r\n========\r\n近期電影列表(指令:電影列表)";
                                break;

                            case string str when str.Contains("座運勢"):
                                Message = service.GetHoroscope(str.Substring(0, 3));

                                break;

                            case string str when str.Contains("電影列表"):
                                Message = service.GetMovieList();

                                break;

                            case "Hi":
                                Message = "Hello";
                                break;

                            case string str when str.Contains("抽動物"):
                                string ani_url = "https://" + HttpContext.Current.Request.Url.Host + service.GetAnimalImg();

                                Utility.ReplyImageMessage(item.replyToken, ani_url, ani_url, ChannelAccessToken);
                                break;

                            case "查詢電影":
                                var question = service.AddQuestion(item.source.userId);
                                if (question != "")
                                {
                                    MessageAction[] actions =
                                    {
                                        new MessageAction {
                                            label = "威秀影城", text = "威秀"
                                        },
                                        new MessageAction {
                                            label = "國賓影城", text = "國賓"
                                        }
                                    };
                                    var ButtonTemplate = GetButtonsTemplate(question, question, $"{question}", actions);
                                    Utility.ReplyTemplateMessage(item.replyToken, ButtonTemplate, ChannelAccessToken);
                                }
                                else
                                {
                                    Utility.ReplyMessage(item.replyToken, "請先結束當前問題!", ChannelAccessToken);
                                }
                                break;

                            default:
                                break;
                            }
                        }

                        //取得用戶名稱
                        //LineUserInfo UserInfo = null;
                        //if (item.source.type.ToLower() == "room")
                        //    UserInfo = Utility.GetRoomMemberProfile(
                        //        item.source.roomId, item.source.userId, ChannelAccessToken);
                        //if (item.source.type.ToLower() == "group")
                        //    UserInfo = Utility.GetGroupMemberProfile(
                        //        item.source.groupId, item.source.userId, ChannelAccessToken);
                        //顯示用戶名稱
                        //if (item.source.type.ToLower() != "user")
                        //    Message += "\n你是:" + UserInfo.displayName;
                        //回覆用戶
                        if (Message != "")
                        {
                            Utility.ReplyMessage(item.replyToken, Message, ChannelAccessToken);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                return(Ok(HttpContext.Current.Request.Url.Host));
            }

            return(Ok());
        }