Пример #1
0
    /// <summary>
    /// Create room webhook
    /// </summary>
    /// <param name="room">The room.</param>
    /// <param name="url">The URL.</param>
    /// <param name="webhookEvent">The webhook event.</param>
    /// <param name="name">The name.</param>
    /// <param name="pattern">The pattern.</param>
    /// <returns>Task&lt;IResponse&lt;System.Boolean&gt;&gt;.</returns>
    public async Task<IResponse<bool>> CreateWebhookAsync(string room, Uri url, WebhookEvent webhookEvent, string name = null, string pattern = null)
    {
      var hook = new CreateWebhook
      {
        Url = url.AbsoluteUri,
        Event = webhookEvent,
        Name = string.Format("HipChatDotNet_{0}", name ?? "Default")
      };
      if (pattern != null && (webhookEvent == WebhookEvent.RoomMessage || webhookEvent == WebhookEvent.RoomNotification))
        hook.Pattern = pattern;

      return await CreateWebhookAsync(room, hook);
    }
Пример #2
0
    /// <summary>
    /// Create room webhook
    /// </summary>
    /// <param name="room">The room.</param>
    /// <param name="hook">The hook.</param>
    /// <returns>Task&lt;IResponse&lt;System.Boolean&gt;&gt;.</returns>
    public async Task<IResponse<bool>> CreateWebhookAsync(string room, CreateWebhook hook)
    {
      Validate.Length(room, 100, "Room Id/Name");
      Validate.NotEmpty(hook.Url, "Webhook URL");

      var json = JsonConvert.SerializeObject(hook, Formatting.None, _jsonSettings);
      var payload = new StringContent(json, Encoding.UTF8, "application/json");

      var result = await ApiConnection.Client.PostAsync(string.Format("room/{0}/webhook", room), payload);
      var content = await result.Content.ReadAsStringAsync();
      var response = new Response<bool>(true)
      {
        Code = result.StatusCode,
        Body = content,
        ContentType = result.Content.Headers.ContentType.MediaType
      };
      return response;
    }