/// <summary> /// Send a message to a room /// </summary> /// <param name="roomName">The name of the room</param> /// <param name="message">message to send</param> /// <param name="backgroundColor">the background color of the message, only applicable to html format message</param> /// <param name="notify">if the message should notify</param> /// <param name="messageFormat">the format of the message</param> /// <returns>true if the message was sucessfully sent</returns> /// <remarks> /// Auth required with scope 'view_group'. https://www.hipchat.com/docs/apiv2/method/send_room_notification /// </remarks> public bool SendNotification(string roomName, string message, RoomColors backgroundColor = RoomColors.Yellow, bool notify = false, HipchatMessageFormat messageFormat = HipchatMessageFormat.Html) { using (JsonSerializerConfigScope()) { var request = new SendRoomNotificationRequest { Color = backgroundColor, Message = message, MessageFormat = messageFormat, Notify = notify }; return(SendNotification(roomName, request)); } }
/// <summary> /// Send a message to a room /// </summary> /// <param name="roomName">The id of the room</param> /// <param name="request">The request containing the info about the notification to send</param> /// <returns>true if the message successfully sent</returns> /// <remarks> /// Auth required with scope 'view_group'. https://www.hipchat.com/docs/apiv2/method/send_room_notification /// </remarks> public bool SendNotification(string roomName, SendRoomNotificationRequest request) { using (JsonSerializerConfigScope()) { if (request.Message.IsEmpty() || request.Message.Length > 10000) { throw new ArgumentOutOfRangeException("request", "message length must be between 0 and 10k characters"); } var result = false; try { HipchatEndpoints.SendNotificationEndpointFormat .Fmt(roomName) .AddHipchatAuthentication() .PostJsonToUrl(request, null, x => { if (x.StatusCode == HttpStatusCode.NoContent) { result = true; } }); } catch (Exception exception) { if (exception is WebException) { throw ExceptionHelpers.WebExceptionHelper(exception as WebException, "send_notification"); } throw ExceptionHelpers.GeneralExceptionHelper(exception, "SendNotification"); } return(result); } }
/// <summary> /// Send a message to a room /// </summary> /// <param name="roomId">The id of the room</param> /// <param name="request">The request containing the info about the notification to send</param> /// <returns>true if the message successfully sent</returns> /// <remarks> /// Auth required with scope 'view_group'. https://www.hipchat.com/docs/apiv2/method/send_room_notification /// </remarks> public bool SendNotification(int roomId, SendRoomNotificationRequest request) { return(SendNotification(roomId.ToString(), request)); }