Esempio n. 1
0
        /// <summary>
        /// 处理文字消息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        {
            //关键字回复
            var keyWordHandler = requestMessage.StartHandler(false)
                                 .Keyword("cmd", () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();
                var storageModel    = new StorageModel()
                {
                    IsInCmd = true
                };

                base.GetCurrentMessageContext().Result.StorageData = storageModel;

                responseMessage.Content = "您进入了CDM模式";

                return(responseMessage);
            }).Keywords(new string[] { "exit", "quit", "close" }, () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();
                var storageModel    = base.GetCurrentMessageContext().Result.StorageData as StorageModel;


                if (storageModel != null)
                {
                    storageModel.IsInCmd = false;
                }

                responseMessage.Content = "您退出了CMD模式";

                return(responseMessage);
            }).Regex(@"^http", () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageNews>();

                var article = new Article
                {
                    Description = "你看看这里\r\n有换行\r\n再换行",
                    PicUrl      = "https://sdk.weixin.senparc.com/images/book-cover-front-small-3d-transparent.png",
                    Title       = "您输入了:" + requestMessage.Content,
                    Url         = "https://sdk.weixin.senparc.com/"
                };

                responseMessage.Articles.Add(article);

                return(responseMessage);
            }).Regex(@"天气 \S+", () =>
            {
                var cityCode = Regex.Match(requestMessage.Content, @"(?<=天气 )(\S+)").Value;

                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();

                string url  = "http://t.weather.itboy.net/api/weather/city/{0}".FormatWith(cityCode);
                var weather = Senparc.CO2NET.HttpUtility.Get.GetJson <Weather>(null, url);

                string strResponText = @"天气:
message:{0}
status:{1}
date:{2}
time:{3}".FormatWith(weather.message, weather.status, weather.date, weather.time);

                responseMessage.Content = strResponText;

                return(responseMessage);
            }).Keyword("123", () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();

                responseMessage.Content = "关键字回复:" + requestMessage.Content;

                return(responseMessage);
            }).Default(() =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();

                responseMessage.Content = "您输入了文字:" + requestMessage.Content;

                return(responseMessage);
            });


            return(keyWordHandler.ResponseMessage);
        }
        /// <summary>
        /// 处理文字消息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        {
            //关键字回复
            var keyWordHandler = requestMessage.StartHandler(false)
                                 .Keyword("cmd", () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();
                var storageModel    = new StorageModel()
                {
                    IsInCmd = true
                };

                base.GetCurrentMessageContext().Result.StorageData = storageModel;

                responseMessage.Content = "您进入了CDM模式";

                return(responseMessage);
            }).Keywords(new string[] { "exit", "quit", "close" }, () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();
                var storageModel    = base.GetCurrentMessageContext().Result.StorageData as StorageModel;


                if (storageModel != null)
                {
                    storageModel.IsInCmd = false;
                }

                responseMessage.Content = "您退出了CMD模式";

                return(responseMessage);
            }).Regex(@"^http", () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageNews>();

                var article = new Article
                {
                    Description = "你看看这里\r\n有换行\r\n再换行",
                    PicUrl      = "https://sdk.weixin.senparc.com/images/book-cover-front-small-3d-transparent.png",
                    Title       = "您输入了:" + requestMessage.Content,
                    Url         = "https://sdk.weixin.senparc.com/"
                };

                responseMessage.Articles.Add(article);

                return(responseMessage);
            }).Keyword("123", () =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();

                responseMessage.Content = "关键字回复:" + requestMessage.Content;

                return(responseMessage);
            }).Default(() =>
            {
                var responseMessage = this.CreateResponseMessage <ResponseMessageText>();

                responseMessage.Content = "您输入了文字:" + requestMessage.Content;

                return(responseMessage);
            });


            return(keyWordHandler.ResponseMessage);
        }