/// <summary>
        /// 返回文字类型信息
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <param name="responseConfig"></param>
        /// <returns></returns>
        private IResponseMessageText RenderResponseMessageText(IRequestMessageBase requestMessage, Response responseConfig, MessageEntityEnlightener enlighten)
        {
            var strongResponseMessage = requestMessage.CreateResponseMessage <IResponseMessageText>(enlighten);

            strongResponseMessage.Content = NeuralNodeHelper.FillTextMessage(responseConfig.GetMaterialContent(MaterialData));
            return(strongResponseMessage);
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// 执行API
        /// </summary>
        /// <param name="response"></param>
        /// <param name="requestMessage"></param>
        /// <param name="accessTokenOrAppId"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public ApiResult ExecuteApi(Response response, IRequestMessageBase requestMessage, string accessTokenOrAppId, string openId)
        {
            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.Content);
                    apiResult = ApiEnlighten.SendText(accessTokenOrAppId, openId, cotnent);
                    break;

                case ResponseMsgType.News:
                    break;

                case ResponseMsgType.Music:
                    break;

                case ResponseMsgType.Image:
                    var mediaId = NeuralNodeHelper.GetImageMessageMediaId(requestMessage, response.Content);
                    SenparcTrace.SendCustomLog("ExecuteApi-Image", $"mediaId:{mediaId}");
                    if (true)
                    {
                        //TODO:其他mediaId的情况
                    }
                    apiResult = 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 = ApiEnlighten.CustomApi(response, 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);
        }