public async static Task <bool> SendOperationCompleteNotificationAsync(Response responseObj)
        {
            NotificationMessageBody fcmMessageBody = new NotificationMessageBody();;
            bool respValue = false;
            HttpResponseMessage httpResponseMessage = null;

            HttpClient httpClient = new HttpClient();

            httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            switch (responseObj.FlowMap.NotificationType)
            {
            case NotificationType.Targeted:
                var userMessageRequest = new UserMessageRequest();
                userMessageRequest.UserId     = responseObj.UserId;
                userMessageRequest.ResponseId = responseObj._id;

                userMessageRequest.MessageContent       = new MessageContent();
                userMessageRequest.MessageContent.title = responseObj.FlowMap.CMSOperation + " complete";
                fcmMessageBody.NotificationType         = NotificationType.Targeted;
                fcmMessageBody.NotificationTopic        = NotificationTopic.NA;
                fcmMessageBody.ResponseId              = responseObj._id;
                fcmMessageBody.CMSOperation            = responseObj.FlowMap.CMSOperation;
                userMessageRequest.MessageContent.body = fcmMessageBody;
                httpResponseMessage = await httpClient.PostJsonAsync <UserMessageRequest>(NotificationReceiverConfigSettings.UrlSendMessageToUser, userMessageRequest);

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    respValue = true;
                }
                break;

            case NotificationType.Broadcast:
                var topicMessageRequest = new TopicMessageRequest();
                topicMessageRequest.ResponseId   = responseObj._id;
                topicMessageRequest.TopicPattern = responseObj.FlowMap.NotificationTopic;

                topicMessageRequest.MessageContent       = new MessageContent();
                topicMessageRequest.MessageContent.title = responseObj.FlowMap.CMSOperation + " complete";
                fcmMessageBody.NotificationType          = NotificationType.Broadcast;
                fcmMessageBody.NotificationTopic         = responseObj.FlowMap.NotificationTopic;
                fcmMessageBody.ResponseId               = responseObj._id;
                fcmMessageBody.CMSOperation             = responseObj.FlowMap.CMSOperation;
                topicMessageRequest.MessageContent.body = fcmMessageBody;
                httpResponseMessage = await httpClient.PostJsonAsync <TopicMessageRequest>(NotificationReceiverConfigSettings.UrlSendMessageToTopic, topicMessageRequest);

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    respValue = true;
                }
                break;
            }

            return(respValue);
        }
 public ActionResult ChatMessage(UserMessageRequest model)
 {
     if (ModelState.IsValid)
     {
         var message = new UserMessage()
         {
             Id          = Guid.NewGuid(),
             MessageText = model.MessageText,
             SendDate    = DateTime.Now,
             ReceiverApplicationUserId = model.ReceiverApplicationUserId,
             SenderApplicationUserId   = model.SenderApplicationUserId
         };
         UnitOfWork.UserMessageRepository.Add(message);
         UnitOfWork.Commit();
         return(Ok(new BaseResponse {
             IsSuccess = true, Message = "Mesaj Gönderildi"
         }));
     }
     return(Ok(ReturnValidationError()));
 }
Exemplo n.º 3
0
        public async Task <bool> SendMessageToUserAsync(UserMessageRequest message)
        {
            var device = await this._userDeviceRepository.GetDocumentAsync(message.UserId);

            var     url     = this._fcmAppSettings.TopicUnRegisterUrl;
            dynamic request = new ExpandoObject();

            request.to           = device.NotificationKey;
            request.notification = message.MessageContent;

            var response = await this._httpClient.PostJsonAsync <ExpandoObject>(this._fcmAppSettings.FCMMessageSendingUrl, (ExpandoObject)request);

            //TODO:The Call will return you partial success,the app server should retry with back off between retries.
            // For Now only checking the Success of the call not the partial success.
            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }