private async Task <PNResult <PNAddMessageActionResult> > Publish(string channel, long messageTimetoken, PNMessageAction messageAction, Dictionary <string, object> externalQueryParam)
        {
            PNResult <PNAddMessageActionResult> ret = new PNResult <PNAddMessageActionResult>();

            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()) || messageAction == null)
            {
                PNStatus status = new PNStatus();
                status.Error     = true;
                status.ErrorData = new PNErrorData("Missing Channel or MessageAction", new ArgumentException("Missing Channel or MessageAction"));
                ret.Status       = status;
                return(ret);
            }

            if (string.IsNullOrEmpty(config.SubscribeKey) || string.IsNullOrEmpty(config.SubscribeKey.Trim()) || config.SubscribeKey.Length <= 0)
            {
                PNStatus status = new PNStatus();
                status.Error     = true;
                status.ErrorData = new PNErrorData("Invalid subscribe key", new MissingMemberException("Invalid subscribe key"));
                ret.Status       = status;
                return(ret);
            }

            string requestMethodName = "POST";
            string postMessage       = jsonLibrary.SerializeToJsonString(messageAction);

            byte[]             postData   = Encoding.UTF8.GetBytes(postMessage);
            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildAddMessageActionRequest(requestMethodName, postMessage, channel, messageTimetoken, externalQueryParam);

            RequestState <PNAddMessageActionResult> requestState = new RequestState <PNAddMessageActionResult>();

            requestState.Channels          = new[] { channel };
            requestState.ResponseType      = PNOperationType.PNAddMessageActionOperation;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;
            requestState.UsePostMethod     = true;

            Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false, postData).ConfigureAwait(false);

            ret.Status = JsonAndStatusTuple.Item2;
            string json = JsonAndStatusTuple.Item1;

            if (!string.IsNullOrEmpty(json))
            {
                List <object>            resultList      = ProcessJsonResponse(requestState, json);
                ResponseBuilder          responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog);
                PNAddMessageActionResult responseResult  = responseBuilder.JsonToObject <PNAddMessageActionResult>(resultList, true);
                if (responseResult != null)
                {
                    ret.Result = responseResult;
                }
            }

            return(ret);
        }
        private void Publish(string channel, long messageTimetoken, PNMessageAction messageAction, Dictionary <string, object> externalQueryParam, PNCallback <PNAddMessageActionResult> callback)
        {
            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()) || messageAction == null)
            {
                PNStatus status = new PNStatus();
                status.Error     = true;
                status.ErrorData = new PNErrorData("Missing Channel or MessageAction", new ArgumentException("Missing Channel or MessageAction"));
                callback.OnResponse(null, status);
                return;
            }

            if (string.IsNullOrEmpty(config.SubscribeKey) || string.IsNullOrEmpty(config.SubscribeKey.Trim()) || config.SubscribeKey.Length <= 0)
            {
                PNStatus status = new PNStatus();
                status.Error     = true;
                status.ErrorData = new PNErrorData("Invalid subscribe key", new MissingMemberException("Invalid subscribe key"));
                callback.OnResponse(null, status);
                return;
            }

            if (callback == null)
            {
                return;
            }

            string requestMethodName = "POST";
            string postMessage       = jsonLibrary.SerializeToJsonString(messageAction);

            byte[]             postData   = Encoding.UTF8.GetBytes(postMessage);
            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildAddMessageActionRequest(requestMethodName, postMessage, channel, messageTimetoken, externalQueryParam);

            RequestState <PNAddMessageActionResult> requestState = new RequestState <PNAddMessageActionResult>();

            requestState.Channels          = new[] { channel };
            requestState.ResponseType      = PNOperationType.PNAddMessageActionOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;
            requestState.UsePostMethod     = true;

            UrlProcessRequest(request, requestState, false, postData).ContinueWith(r =>
            {
                string json = r.Result.Item1;
                if (!string.IsNullOrEmpty(json))
                {
                    List <object> result = ProcessJsonResponse(requestState, json);

                    ProcessResponseCallbacks(result, requestState);
                }
                CleanUp();
            }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        }