public IActionResult SendMessage(SendMessageReq pReq) { try { if (!ModelState.IsValid) { StringBuilder wStr = new StringBuilder(); wStr.AppendLine("Some data is invalid"); if (string.IsNullOrEmpty(pReq.PhoneNumberTo)) { wStr.AppendLine("PhoneNumberTo in url param required"); } if (string.IsNullOrEmpty(pReq.PhoneNumber)) { wStr.AppendLine("PhoneNumber required"); } ApiErrorResponse wResp = new ApiErrorResponse(HttpStatusCode.BadRequest, wStr.ToString()); ObjectResult wObjRes = this.StatusCode(400, wResp); return(wObjRes); } service.TestMessage(pReq); return(Ok()); } catch (Exception ex) { apiLogServices.LogError_asynk(ex); return(BadRequest(ex.Message)); } }
public void TestMessage(SendMessageReq pReq) { try { MessageBE msg = new MessageBE(); #region Mapping BE msg.Body = pReq.PhoneNumberTo; msg.UserName = pReq.FirstName; msg.Mail = pReq.Mail; msg.CreatedDate = CommonHelpers.ToEpoch(DateTime.Now); #endregion } catch (Exception ex) { throw ex; } }
public async Task SendMessage(SendMessageReq req, DatabaseContext context) { var currentUserData = this._currentUserService.GetCurrentUserData(); string senderId; string receiverId; var connection = await context.Connections .Include(c => c.ExpertProfile.User) .Include(c => c.Vacancy.Event.Company) .SingleAsync(c => c.Id == req.ConnectionId); var expertUserId = connection.ExpertProfile.UserId; var companyUserId = connection.Vacancy.Event.Company.UserId; if (expertUserId == currentUserData.Id) { senderId = expertUserId; receiverId = companyUserId; } else if (companyUserId == currentUserData.Id) { senderId = companyUserId; receiverId = expertUserId; } else { throw new Exception(); } var message = new ChatMessage { ConnectionId = req.ConnectionId, Body = req.Body, SendTime = DateTime.Now, Direction = senderId == expertUserId ? ChatMessageDirections.ExpertToCompany : ChatMessageDirections.VacancyToExpert }; context.ChatMessages.Add(message); await context.SaveChangesAsync(); await this.MessageReadyForDelivery.Invoke( new Message { Id = message.Id, Direction = message.Direction, Body = req.Body, ConnectionId = req.ConnectionId, ConnectionType = connection.ConnectionType, ExpertId = connection.ExpertProfileId, ExpertName = connection.ExpertProfile.User.DisplayName, CompanyId = connection.Vacancy.Event.CompanyId, CompanyName = connection.Vacancy.Event.Company.Name, SendTime = DateTime.Now, }, senderId, receiverId ); }
public static SendMessageResp SendMessage(SendMessageReq req) { req.Content = Convert.ToBase64String(Class1.Gzip(System.Text.Encoding.Default.GetBytes(req.Content))); var ret = Class1.DoHttpRequest("/message", "POST", new Dictionary <string, string> { { "access_token", Class1.AccessToken } }, JsonConvert.SerializeObject(req)); var resp = JsonConvert.DeserializeObject <SendMessageResp>(ret); return(resp); }
public async Task SendMessageToAll(SendMessageReq req, DatabaseContext context) { var connections = await context.Connections .Where(c => c.Vacancy.Connections.Any(cc => cc.Id == req.ConnectionId)) .ToArrayAsync(); foreach (var c in connections) { await this.SendMessage(new SendMessageReq { ConnectionId = c.Id, Body = req.Body }, context); } }
public IActionResult SendBindMessage([FromBody] SendMessageReq sendMessage) { try { if (!ValidateHelper.IsPhoneFormat(sendMessage.Phone)) { return(Json(new JsonResultModel(ReturnCode.ParameterError, "Phone format is not correct."))); } var reply = Client.SendBindMessage(sendMessage); //发送短信 string msg_code = ""; string msg_msg = ""; string message = MsgContent(sendMessage.Phone, reply.Code); bool result = MsgService.SendMessage(sendMessage.Phone, message, out msg_code, out msg_msg); //保存发送记录到数据库 var msgRecord = new RecordMessageReq() { Destination = sendMessage.Phone, Message = message, SendStatus = result ? MsgSendStatus.Success : MsgSendStatus.Failed, ReturnMessage = msg_msg }; if (TiantianMsg.Config.EnableMsg) { Client.RecordMessageInfo(msgRecord); } if (!result) { return(Json(new JsonResultModel(ReturnCode.MessageError, msg_msg))); } return(Json(new JsonResultModel(ReturnCode.Success, "Bind phone text message send to user successful."))); } catch (RpcException ex) { return(Json(new JsonResultModel(ReturnCode.SubmitError, ex.Status.Detail))); } }