예제 #1
0
        public async Task <IHttpActionResult> Subscribe(SubscriptionNotificationRequestDto ideaMartResponse)
        {
            //Log.TraceStart();
            //Log.Data("IdeaMartResponseDto: ", ideaMartResponse);

            IdeaMartStatusResponseDto statusResponse = new IdeaMartStatusResponseDto();

            try
            {
                var subscriberId = (_environment == "prod") ? "tel:" + ideaMartResponse.subscriberId : ideaMartResponse.subscriberId;
                var status       = ideaMartResponse.status;

                if (status == "REGISTERED")// Register
                {
                    RegisterUser(subscriberId);
                }
                else if (status == "UNREGISTERED")// Unregister
                {
                    UnregisterUser(subscriberId);
                }

                statusResponse.requestId    = "";
                statusResponse.statusCode   = Consts.SUCCESS;
                statusResponse.statusDetail = Consts.SUCCESS;
                statusResponse.timeStamp    = DateTime.UtcNow.ToString();
                statusResponse.version      = ideaMartResponse.version;
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return(BadRequest());
            }
            return(Ok(statusResponse));
        }
예제 #2
0
        public async Task <IHttpActionResult> Send(IdeaMartResponse ideaMartResponse)
        {
            //SIMULATOR Application Data: //URL: http://localhost:41440/api/v1/userchat/send

            IdeaMartStatusResponseDto statusResponse = new IdeaMartStatusResponseDto();
            var receivedMsg = ideaMartResponse.message;
            var userAddress = ideaMartResponse.sourceAddress;

            try
            {
                var receivedMsgArray = receivedMsg.Split(' ');

                //Validate message
                if (receivedMsgArray == null || receivedMsgArray.Length < 2)
                {
                    Sms.Send(userAddress, Resources.Error_InvalidInputMessage);
                    BadRequest();
                }

                var key1 = receivedMsgArray[0].ToUpper();
                var key2 = receivedMsgArray[1].ToUpper();

                if (key1 == ShortKey.REG.ToString() && key2 == ShortKey.CC.ToString())// Register
                {
                    statusResponse = await RegisterUser(userAddress);
                }
                else if (key1 == ShortKey.UNREG.ToString() && key2 == ShortKey.CC.ToString())// Unregister
                {
                    statusResponse = await UnregisterUser(userAddress);
                }
                else if (key1 == ShortKey.CC.ToString() && key2.Length == _codeLength)// send chat sms
                {
                    Chat(userAddress, receivedMsg);
                    statusResponse.requestId    = ideaMartResponse.requestId;
                    statusResponse.statusCode   = Consts.SUCCESS;
                    statusResponse.statusDetail = Consts.SUCCESS;
                    statusResponse.timeStamp    = DateTime.UtcNow.ToString();
                    statusResponse.version      = ideaMartResponse.version;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return(BadRequest());
            }
            return(Ok(statusResponse));
        }
예제 #3
0
        /// <summary>
        /// Subscribe user from an application.
        /// </summary>
        /// <param name="applicationId"></param>
        /// <param name="password"></param>
        /// <param name="subscriberId"></param>
        /// <returns></returns>
        public async Task <IdeaMartStatusResponseDto> Add(string applicationId, string password, string subscriberId)
        {
            //Log.TraceStart();
            IdeaMartStatusResponseDto response = null;

            try
            {
                SubscriptionRequestDto subscriptionRequestDto = new SubscriptionRequestDto();
                subscriptionRequestDto.applicationId = applicationId;
                subscriptionRequestDto.password      = password;
                subscriptionRequestDto.subscriberId  = subscriberId;
                subscriptionRequestDto.action        = "1";
                subscriptionRequestDto.version       = "1.0";

                var subscriptionResponse = await SubscribeUser(subscriptionRequestDto);

                if (subscriptionResponse.IsSuccessStatusCode)
                {
                    var result = subscriptionResponse.Content.ReadAsAsync <dynamic>().Result;

                    response              = new IdeaMartStatusResponseDto();
                    response.requestId    = result.requestId;
                    response.statusCode   = result.statusCode;
                    response.statusDetail = result.statusDetail;
                    response.timeStamp    = DateTime.UtcNow.ToString();
                    response.version      = result.version;
                }
                else
                {
                    Log.Error(Resources.Subscription_SubscriptionServiceFailed);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }

            //Log.TraceEnd();
            return(response);
        }
예제 #4
0
        public async Task <IHttpActionResult> Send(IdeaMartResponseDto ideaMartResponse)
        {
            //Log.TraceStart();
            //Log.Data("IdeaMartResponseDto: ", ideaMartResponse );
            IdeaMartStatusResponseDto statusResponse = new IdeaMartStatusResponseDto();

            try
            {
                var receivedMsg      = ideaMartResponse.message.Trim();
                var userAddress      = ideaMartResponse.sourceAddress;
                var receivedMsgArray = receivedMsg.Split(' ');

                //Validate message
                if (receivedMsgArray == null || receivedMsgArray.Length < 2 || receivedMsgArray[0].ToUpper() != ShortKey.CC.ToString())
                {
                    Sms.Send(userAddress, Resources.Error_InvalidInputMessage);
                    BadRequest();
                }

                var key1    = receivedMsgArray[0].ToUpper();
                var message = receivedMsg.Substring(key1.Length + 1);

                if (message.Substring(0, 1) == "#")
                {
                    var key2 = receivedMsgArray[1].ToUpper();

                    if (key2 == @"#HELP" && receivedMsgArray.Length == 2)// Help
                    {
                        message = Resources.Info_Help;
                        Sms.Send(userAddress, message);
                    }
                    else if (key2 == @"#DEL" && receivedMsgArray.Length == 2)// Delete linked users
                    {
                        RemoveUser(userAddress);
                    }
                    else if (key2 == @"#CODE" && receivedMsgArray.Length == 2)// Get Code
                    {
                        GetCode(userAddress);
                    }
                    else if (key2 == @"#ADD" && receivedMsgArray.Length > 2) // Link user
                    {
                        var code = receivedMsgArray[2].ToUpper();            //for couple user
                        LinkUser(userAddress, code);
                    }
                    else if (key2 == @"#PATS" && receivedMsgArray.Length == 2)// Get user count
                    {
                        GetUserCount(userAddress);
                    }
                    else if (key2.Substring(0, 1) == @"#" && receivedMsgArray.Length > 2)//Send to specific user
                    {
                        var code = key2.Substring(1);
                        message = message.Substring(key2.Length + 1);
                        SendSmsByCode(userAddress, code, message);
                    }
                    else
                    {
                        message = Resources.Error_InvalidSmsFormat;
                        Sms.Send(userAddress, message);
                    }
                }
                else // send sms to linked user
                {
                    SendSmsToLinkedUser(userAddress, message);
                }

                statusResponse.requestId    = ideaMartResponse.requestId;
                statusResponse.statusCode   = Consts.SUCCESS;
                statusResponse.statusDetail = Consts.SUCCESS;
                statusResponse.timeStamp    = DateTime.UtcNow.ToString();
                statusResponse.version      = ideaMartResponse.version;
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return(BadRequest());
            }
            return(Ok(statusResponse));
        }