Esempio n. 1
0
        /// <summary>
        /// 返回图文类型信息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <param name="responseConfig"></param>
        /// <returns></returns>
        private IResponseMessageNews RenderResponseMessageNews(IRequestMessageBase requestMessage, Response responseConfig, MessageEntityEnlightener enlighten)
        {
            var strongResponseMessage = requestMessage.CreateResponseMessage <IResponseMessageNews>(enlighten);

            strongResponseMessage.Articles = NeuralNodeHelper.FillNewsMessage(responseConfig.Content);
            return(strongResponseMessage);
        }
Esempio n. 2
0
        /// <summary>
        /// 返回图文类型信息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <param name="responseConfig"></param>
        /// <returns></returns>
        private IResponseMessageNews RenderResponseMessageNews(IRequestMessageBase requestMessage, Response responseConfig, MessageEntityEnlightener enlighten)
        {
            var articles = NeuralNodeHelper.FillNewsMessage(responseConfig.MaterialId, MaterialData);
            var strongResponseMessage = requestMessage.CreateResponseMessage <IResponseMessageNews>(enlighten);

            if (articles != null)
            {
                strongResponseMessage.Articles = articles;
            }
            else
            {
                strongResponseMessage.Articles = new List <Article>()
                {
                    new Article()
                    {
                        Title       = "您要查找的素材不存在,或格式定义错误!",
                        Description = "您要查找的素材不存在,或格式定义错误!"
                    }
                };
            }
            return(strongResponseMessage);
        }
Esempio n. 3
0
        /// <summary>
        /// 执行API
        /// </summary>
        /// <param name="response"></param>
        /// <param name="materialData"></param>
        /// <param name="requestMessage"></param>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public async Task <ApiResult> ExecuteApi(Response response, MaterialData materialData, IRequestMessageBase requestMessage, string accessTokenOrAppId, string openId, IMessageHandlerEnlightener enlightener)
        {
            if (response == null)
            {
                return(new ApiResult(-1, "未获取到响应消息设置", null));
            }

            ApiResult apiResult = null;

            try
            {
                switch (response.Type)
                {
                case ResponseMsgType.Unknown:
                    break;

                case ResponseMsgType.Text:
                    var cotnent = NeuralNodeHelper.FillTextMessage(response.GetMaterialContent(materialData));
                    apiResult = await ApiEnlighten.SendText(accessTokenOrAppId, openId, cotnent);

                    break;

                case ResponseMsgType.News:
                {
                    var articles = NeuralNodeHelper.FillNewsMessage(response.MaterialId /*"9DAAC45C|6309EAD9"*/, materialData);
                    if (articles == null)
                    {
                        apiResult = await ApiEnlighten.SendText(accessTokenOrAppId, openId, "您要查找的素材不存在,或格式定义错误!");
                    }
                    else
                    {
                        apiResult = await ApiEnlighten.SendNews(accessTokenOrAppId, openId, articles);
                    }
                }
                break;

                case ResponseMsgType.Music:
                    break;

                case ResponseMsgType.Image:
                    var mediaId = NeuralNodeHelper.GetImageMessageMediaId(requestMessage, response.GetMaterialContent(materialData));
                    SenparcTrace.SendCustomLog("ExecuteApi-Image", $"mediaId:{mediaId}");
                    if (true)
                    {
                        //TODO:其他mediaId的情况
                    }
                    apiResult = await ApiEnlighten.SendImage(accessTokenOrAppId, openId, mediaId);

                    break;

                case ResponseMsgType.Voice:
                    break;

                case ResponseMsgType.Video:
                    break;

                case ResponseMsgType.Transfer_Customer_Service:
                    break;

                case ResponseMsgType.MpNews:
                    break;

                case ResponseMsgType.MultipleNews:
                    break;

                case ResponseMsgType.LocationMessage:
                    break;

                case ResponseMsgType.NoResponse:
                    break;

                case ResponseMsgType.SuccessResponse:
                    break;

                case ResponseMsgType.UseApi:
                    apiResult = await ApiEnlighten.CustomApi(response, materialData, requestMessage.FromUserName);

                    break;

                default:
                    apiResult = new ApiResult(-1, "未找到支持的响应消息类型", null);
                    break;
                }
            }
            catch (Exception ex)
            {
                new MessageHandlerException("NeuChar API调用过程发生错误:" + ex.Message, ex);
                return(new ApiResult(-1, "API调用过程发生错误!", null));
            }


            return(apiResult);
        }