Exemplo n.º 1
0
        public IHttpActionResult POST()
        {
            try
            {
                var author  = "";
                var message = "";



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

                //定義資訊蒐集者
                isRock.LineBot.Conversation.InformationCollector <LeaveRequest> CIC =
                    new isRock.LineBot.Conversation.InformationCollector <LeaveRequest>(ChannelAccessToken);
                //定義接收CIC結果的類別
                ProcessResult <LeaveRequest> CICresult;

                //設定ChannelAccessToken(或抓取Web.Config)
                this.ChannelAccessToken = Properties.Settings.Default["ChannelAccessToken"].ToString();

                this.PushMessage("U849bacfde38571008bbcb71d1f0017a9", "WWWWWWW");
                //取得Line Event
                isRock.LineBot.Event LineEvent = this.ReceivedMessage.events.FirstOrDefault();

                //Uid
                string Uid = LineEvent.source.userId;

                if (LineEvent.message.text == "人生")
                {
                    var windom = _LifeRepo.Get();
                    message     = windom.message;
                    author      = "———" + windom.author;
                    responseMsg = message + author;

                    this.ReplyMessage(LineEvent.replyToken, responseMsg);
                }
                else if (LineEvent.message.text == "愛情")
                {
                    var windom = _LoveRepo.Get();
                    message     = windom.message;
                    author      = "———" + windom.author;
                    responseMsg = message + author;


                    this.ReplyMessage(LineEvent.replyToken, responseMsg);
                }
                else if (LineEvent.message.text == "心靈")
                {
                    var windom = _SoulRepo.Get();
                    message     = windom.message;
                    responseMsg = message;


                    this.ReplyMessage(LineEvent.replyToken, responseMsg);
                }
                else
                {
                    if (ReceivedMessage.events[0].message.text.IndexOf("DISC") >= 0)
                    {
                        dicDISCCount = new Dictionary <string, int>()
                        {
                            { "A", 0 }, { "B", 0 }, { "C", 0 }, { "D", 0 }
                        };

                        //把訊息丟給CIC
                        CICresult = CIC.Process(ReceivedMessage.events[0], true);
                        this.PushMessage(Uid, "請在30秒內回答以下問題");

                        responseMsg = "開始測驗\n";

                        switch (CICresult.ProcessResultStatus)
                        {
                        case ProcessResultStatus.Processed:

                            //ResponseButtonsTemplateCandidate的部分
                            if (CICresult.ResponseButtonsTemplateCandidate != null)
                            {
                                //如果有template Message,直接回覆,否則放到後面一起回覆
                                isRock.LineBot.Utility.ReplyTemplateMessage(
                                    ReceivedMessage.events[0].replyToken,
                                    CICresult.ResponseButtonsTemplateCandidate,
                                    ChannelAccessToken);
                                return(Ok());
                            }

                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        case ProcessResultStatus.Done:
                            responseMsg += CICresult.ResponseMessageCandidate;
                            responseMsg += $"蒐集到的資料有...\n";
                            responseMsg += Newtonsoft.Json.JsonConvert.SerializeObject(CICresult.ConversationState.ConversationEntity);
                            break;

                        case ProcessResultStatus.Pass:
                            responseMsg = $"你說的 '{ReceivedMessage.events[0].message.text}' 我看不懂,如果想要請假,請跟我說 : 『我要請假』";
                            break;

                        case ProcessResultStatus.Exception:
                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        case ProcessResultStatus.Break:
                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        case ProcessResultStatus.InputDataFitError:
                            responseMsg += "\n資料型態不合\n";
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        default:
                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;
                        }

                        isRock.LineBot.Utility.ReplyMessage(ReceivedMessage.events[0].replyToken, responseMsg, ChannelAccessToken);
                    }
                    else
                    {
                        CIC.OnMessageTypeCheck += (s, e) =>
                        {
                            if (e.CurrentPropertyName.IndexOf("Question") >= 0)
                            {
                                string key = e.ReceievedMessage.Substring(0, 1);
                                dicDISCCount[key]++;
                            }
                        };

                        //把訊息丟給CIC
                        CICresult = CIC.Process(ReceivedMessage.events[0]);

                        switch (CICresult.ProcessResultStatus)
                        {
                        case ProcessResultStatus.Processed:

                            //ResponseButtonsTemplateCandidate的部分
                            if (CICresult.ResponseButtonsTemplateCandidate != null)
                            {
                                //如果有template Message,直接回覆,否則放到後面一起回覆
                                isRock.LineBot.Utility.ReplyTemplateMessage(
                                    ReceivedMessage.events[0].replyToken,
                                    CICresult.ResponseButtonsTemplateCandidate,
                                    ChannelAccessToken);
                                return(Ok());
                            }

                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        case ProcessResultStatus.Done:

                            switch (dicDISCCount.Aggregate((x, y) => x.Value > y.Value ? x : y).Key)
                            {
                            case "A":
                                this.PushMessage(Uid, "你是:孔雀 (影響型):外向 多言 樂觀");
                                this.PushMessage(Uid, "特點:一群人裡面說話最多的 天生希望成為注意力的中心,具有很強的好奇心 熱情 熱心具有表達能力 精力充沛 具有幹勁(但是卻缺乏毅力 所以常常這幹幹 那乾幹) 好表現 粗線條 輕許諾(因為熱心所以常常答應別人 但是由於記憶差 所以常常答應後就忘記了) 以自己的快樂為主");
                                this.PushMessage(Uid, "缺點:以自己為中心 獨霸主題 愛打斷別人的談話 不注意記憶 變化無常 這類人易交朋友 但深切的朋友卻不多 喜好多卻不精 缺乏毅力");
                                this.ReplyMessage(ReceivedMessage.events[0].replyToken, "切入點:如果跟這類型的人交往 一定要多誇獎他 多鼓勵他 多給他說話的機會");
                                break;

                            case "B":
                                this.PushMessage(Uid, "你是:老虎 (支配型) : 外向 行動者 樂觀");
                                this.PushMessage(Uid, "特點:喜歡做主 行動力強 行動速度 思考力稍弱 喜歡做目標 不達目的不罷休 充滿自信 意志堅定 有活力 做事主動 不易氣餒 是推動別人行動的人 粗線條 不容易適應環境 (不過由於行動力很強 所以往往做事會有很大成就) ");
                                this.PushMessage(Uid, "缺點:不易看到別人的需求,只看到自己的需求 做錯事後很容易原諒自己 固執 易爭吵 好鬥 說話極易傷害別人 具有強迫性 很容易支配別人 無耐性 專橫 經常人際關係差 (這類人總覺得自己是對的 不太需要朋友,並且這類人天生行動力強 但是即使是正確的事情 也因為性格問題 說話傷害到別人 而得不到別人的支持和認同)");
                                this.ReplyMessage(ReceivedMessage.events[0].replyToken, "注意點:這類型嚴重者會很獨斷 霸道 容易讓別人感到壓力 相處很累");
                                break;

                            case "C":
                                this.PushMessage(Uid, "你是:貓頭鷹 (分析型):內向 思考者 對事物看法較為負面");
                                this.PushMessage(Uid, "特點:以思考為主 深思熟慮 嚴肅 有目標 並且目標感很強 追求完美 有藝術天分 沉悶 關注細節 完美主義 高標準 想得多但做得少 做事前一定要先想個計劃 有條理 有組織 交友慎重(但一旦交往 就會很忠誠的對待朋友) 關心別人 為別人犧牲是自己的意願 (所以這類型的人一生一定有幾個特別好的朋友一輩子的朋友那種)情感豐富容易感動 也容易受傷 高標準–對自己要求高對​​別人要求也高 希望一切都作的很好 很對 、理想主義 朝著自己的目標前進");
                                this.PushMessage(Uid, "缺點:行動力弱 優柔寡斷 容易抑鬱(常常是因為要求過高了 當達不到時候就會很失望)容易自慚自愧 悲觀 天生消極 易受環境影響 情緒化 注意點:這類型的人太容易思考 過分時會情緒低落");
                                this.ReplyMessage(ReceivedMessage.events[0].replyToken, "切入點:如果想和著類型的人合作 一定要先打動他 但是不要急功近利 要一點一點的建立信任和感情 這類型的人 一旦認同你後 會很忠誠 忠心");
                                break;

                            case "D":
                                this.PushMessage(Uid, "你是:無尾熊(穩健型):內向 執行者 追隨者");
                                this.PushMessage(Uid, "特點:性格低調 易相處 很輕鬆 平和 無異議 耐心 適應力強 無攻擊性 很好的聆聽者 人際關係好(和事老) 所以朋友很多 不愛生氣,一但答應下的工作會默默做完");
                                this.PushMessage(Uid, "缺點:不容易興奮 拒絕改變 喜歡一成不變 目標感不強 看似懶惰 不願承擔責任 迴避壓力 沉默、馬虎 無主見(需要力量型的人 給於指導,但不要施加壓力) 不善於做決定");
                                this.PushMessage(Uid, "切入點:和這類型的人交往 一定要鼓勵他 促進他");
                                this.ReplyMessage(ReceivedMessage.events[0].replyToken, "注意點:這類型過分時會毫無主見 做事漫不經心");
                                break;
                            }
                            return(Ok());

                            //responseMsg += CICresult.ResponseMessageCandidate;
                            //responseMsg += $"蒐集到的資料有...\n";
                            //responseMsg += Newtonsoft.Json.JsonConvert.SerializeObject(CICresult.ConversationState.ConversationEntity);
                            break;

                        case ProcessResultStatus.Pass:
                            //回音機器人
                            responseMsg = LineEvent.message.text;
                            this.ReplyMessage(LineEvent.replyToken, "我是回音機器人--你說了[" + responseMsg + "]");
                            //responseMsg = $"你說的 '{ReceivedMessage.events[0].message.text}' 我看不懂,如果想要請假,請跟我說 : 『我要請假』";
                            break;

                        case ProcessResultStatus.Exception:
                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        case ProcessResultStatus.Break:
                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        case ProcessResultStatus.InputDataFitError:
                            responseMsg += "\n資料型態不合\n";
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;

                        default:
                            //取得候選訊息發送
                            responseMsg += CICresult.ResponseMessageCandidate;
                            break;
                        }
                        isRock.LineBot.Utility.ReplyMessage(ReceivedMessage.events[0].replyToken, responseMsg, ChannelAccessToken);
                    }
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                //回覆訊息
                this.PushMessage("!!!改成你的AdminUserId!!!", "發生錯誤:\n" + ex.Message);
                //response OK
                return(Ok());
            }
        }
        //命令列處理
        private List <isRock.LineBot.MessageBase> ProcessCommand(isRock.LineBot.Event lineEvent)
        {
            //把多格空白換成一個
            var cmdLine = MergeSpace(lineEvent.message.text);
            //取消  /  ,以空白做分隔符號,切出
            var words    = cmdLine.ToLower().Replace("/", "").Split(' ').ToList();
            var idOrName = "";
            //回覆訊息物件集合
            var retMessages = new List <isRock.LineBot.MessageBase>();

            //執行api必須的參數
            var AzureDevOpsProjectName      = "";
            var AzureDevOpsOrganizationName = "";
            var AzureDevOpsUserPAT          = "";
            var AzureDevOpsUserName         = "";

            //如果命令中有 setup
            if (words.Contains("setup") && words[0] == "setup")
            {
                //keep data;
                System.Web.HttpContext.Current.Application[lineEvent.source.userId] =
                    $"{words[1]},{words[2]},{words[3]},{words[4]}";
                //System.Web.HttpContext.Current.Application["AzureDevOpsOrganizationName"] = words[1];
                //System.Web.HttpContext.Current.Application["AzureDevOpsProjectName"] = words[2];
                //System.Web.HttpContext.Current.Application["AzureDevOpsUserName"] = words[3];
                //System.Web.HttpContext.Current.Application["AzureDevOpsUserPAT"] = words[4];

                retMessages.Add(new TextMessage("環境參數設定完成!"));
                return(retMessages);
            }


            //取得環境設定
            if (System.Web.HttpContext.Current.Application[lineEvent.source.userId] == null)
            {
                //缺資料,要求輸入
                retMessages.Add(new TextMessage("請先使用 /setup 指令設定環境參數. \n ex. /setup [OrgName] [ProjectName] [UserName] [PAT]"));
                return(retMessages);
            }
            else
            {
                var para = System.Web.HttpContext.Current.Application[lineEvent.source.userId].ToString().Split(',');
                //取得資料
                AzureDevOpsProjectName      = para[1].Trim();
                AzureDevOpsOrganizationName = para[0].Trim();
                AzureDevOpsUserPAT          = para[3].Trim();
                AzureDevOpsUserName         = para[2].Trim();
            }

            //取得approvers
            if (words.Contains("get") && (words.Contains("approver") || words.Contains("approvers")))
            {
                // 建立 AzureDevOpsRestApiClient
                AzureDevOpsRestApiClient client = new AzureDevOpsRestApiClient(
                    AzureDevOpsUserName, AzureDevOpsUserPAT, AzureDevOpsOrganizationName, AzureDevOpsProjectName);
                var ret = client.GetApprovers();
                if (ret != null & ret.count != 0)
                {
                    var ButtonsTemplateMsg = new isRock.LineBot.ButtonsTemplate();
                    var msg = $"共有 {  ret.count} 個等待簽核項目...";

                    ButtonsTemplateMsg.text              = msg;
                    ButtonsTemplateMsg.title             = "等待簽核項目...";
                    ButtonsTemplateMsg.thumbnailImageUrl = new Uri("https://i.imgur.com/pAiJpHg.png");
                    foreach (var item in ret.value)
                    {
                        var action = new isRock.LineBot.MessageAction()
                        {
                            label = $"確定簽核 [編號:{ item.id }]", text = "/Make Approve " + item.id
                        };
                        ButtonsTemplateMsg.actions.Add(action);
                        msg += $"NO.{ item.id } ";
                    }
                    retMessages.Add(new isRock.LineBot.TextMessage(msg));
                    retMessages.Add(new isRock.LineBot.TemplateMessage(ButtonsTemplateMsg));
                }
                else
                {
                    retMessages.Add(new isRock.LineBot.TextMessage($"找不到等待簽核的項目..."));
                }

                return(retMessages);
            }

            //如果命令中有 start & build
            if (words.Contains("start") && words.Contains("build"))
            {
                //找出build後面的元素
                var n = words.FindIndex(c => c == "build");
                if (words.Count() >= n)
                {
                    idOrName = words[n + 1];
                }


                //如果沒有 id, return
                if (string.IsNullOrEmpty(idOrName))
                {
                    return(null);
                }

                // 建立 AzureDevOpsRestApiClient
                AzureDevOpsRestApiClient client = new AzureDevOpsRestApiClient(
                    AzureDevOpsUserName, AzureDevOpsUserPAT, AzureDevOpsOrganizationName, AzureDevOpsProjectName);

                var BuildId = -1;
                //如果id不是數字
                if (int.TryParse(idOrName, out BuildId) == false)
                {
                    //取得id(文字)所對應的build definition
                    var Definitions = client.GetDefinitions();
                    //如果成功取回Definitions
                    if (Definitions != null && Definitions.count > 0)
                    {
                        //找對應名稱的 denifition
                        var Definition = from d in Definitions.value
                                         where d.name.ToLower() == idOrName.ToLower()
                                         select d;
                        if (Definition != null && Definition.Count() >= 1)
                        {
                            //如果有找到對應名稱的 denifition
                            BuildId = Definition.FirstOrDefault().id;
                        }
                        else
                        {
                            retMessages.Add(new isRock.LineBot.TextMessage($"找不到build {idOrName}"));
                            return(retMessages);
                        }
                    }
                    else
                    {
                        retMessages.Add(new isRock.LineBot.TextMessage($"找不到build Definitions"));
                        return(retMessages);
                    }
                }

                //如果找不到build
                if (BuildId <= -1)
                {
                    return(null);
                }

                var ret = client.QueueNewBuild(BuildId);
                if (ret != null)
                {
                    retMessages.Add(new isRock.LineBot.TextMessage($"Build {BuildId} 啟動中... \n Build Name : {ret.definition.name} \n Queue ID : {ret.queue.id} \n buildNumber : {ret.buildNumber}"));
                }
                else
                {
                    retMessages.Add(new isRock.LineBot.TextMessage($"Build {BuildId} 啟動失敗..."));
                }
                return(retMessages);
            }

            if (words.Contains("make") && words.Contains("approve"))
            {
                //找出build後面的元素
                var n = words.FindIndex(c => c == "approve");
                if (words.Count() >= n)
                {
                    idOrName = words[n + 1];
                }

                //如果沒有 id, return
                if (string.IsNullOrEmpty(idOrName))
                {
                    return(null);
                }

                // 建立 AzureDevOpsRestApiClient
                AzureDevOpsRestApiClient client = new AzureDevOpsRestApiClient(
                    AzureDevOpsUserName, AzureDevOpsUserPAT, AzureDevOpsOrganizationName, AzureDevOpsProjectName);


                var ret = client.MakeApprove(int.Parse(idOrName), "ok");

                retMessages.Add(new isRock.LineBot.TextMessage($"單據編號 : {ret.id} {ret.status}"));
                return(retMessages);
            }

            //最後沒有任何指令被執行
            if (retMessages.Count <= 0)
            {
                retMessages.Add(new isRock.LineBot.TextMessage("指令錯誤! 什麼事情都沒發生!"));
                retMessages.Add(new isRock.LineBot.StickerMessage(1, 2));
            }
            return(retMessages);
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
0
 private void DoWork_File(isRock.LineBot.Event LineEvent, string LineID, ref List <isRock.LineBot.MessageBase> response)
 {
     //response.Add(new isRock.LineBot.TextMessage("收到了檔案"));
 }
Exemplo n.º 5
0
 private static void DoWork_Location(isRock.LineBot.Event LineEvent, ref List <isRock.LineBot.MessageBase> response)
 {
     //response.Add(new isRock.LineBot.TextMessage("收到了位置訊息"));
 }
Exemplo n.º 6
0
 private static void DoWork_Sticker(isRock.LineBot.Event LineEvent, ref List <isRock.LineBot.MessageBase> response)
 {
     //response.Add(new isRock.LineBot.TextMessage("收到了表情"));
 }