public void PostWebhook()
        {
            var restClient = MockRestClient
                             .ThatExpects(
                @"{""events"":[""message.created"", ""message.updated""],""channelId"": ""853eeb5348e541a595da93b48c61a1ae"",""url"":""https://example.com/webhook""}")
                             .AndReturns(filename: "WebhookView.json")
                             .FromEndpoint("POST", "webhooks", Resource.ConverstationsBaseUrl)
                             .Get();
            var client = Client.Create(restClient.Object);

            var req = new ConversationWebhook
            {
                ChannelId = "853eeb5348e541a595da93b48c61a1ae",
                Url       = "https://example.com/webhook",
                Events    = new List <ConversationWebhookEvent>
                {
                    ConversationWebhookEvent.MessageCreated, ConversationWebhookEvent.MessageUpdated
                }
            };
            var webhook = client.CreateConversationWebhook(req);

            restClient.Verify();


            Assert.AreEqual(req.ChannelId, webhook.ChannelId);
            Assert.AreEqual(req.Url, webhook.Url);
            Assert.AreEqual(req.Events.Count, webhook.Events.Count);
            Assert.IsTrue(webhook.Events.Contains(ConversationWebhookEvent.MessageCreated));
            Assert.IsTrue(webhook.Events.Contains(ConversationWebhookEvent.MessageUpdated));
        }
        public ConversationWebhook CreateConversationWebhook(ConversationWebhook conversationWebhook)
        {
            ParameterValidator.IsNotNullOrWhiteSpace(conversationWebhook.ChannelId, "channelId");
            ParameterValidator.IsNotNullOrWhiteSpace(conversationWebhook.Url, "url");
            ParameterValidator.ContainsAtLeast(conversationWebhook.Events.ToArray(), 1, "events");

            var resource = new Webhooks(conversationWebhook);

            restClient.Create(resource);

            return(resource.Object as ConversationWebhook);
        }
예제 #3
0
 public static bool CreateWebHook(string hookUrl)
 {
     try
     {
         var req = new ConversationWebhook
         {
             ChannelId = ChannelId,
             Url       = hookUrl,
             Events    = new List <ConversationWebhookEvent>
             {
                 //ConversationWebhookEvent.ConversationCreated, ConversationWebhookEvent.ConversationUpdated,
                 ConversationWebhookEvent.MessageCreated, ConversationWebhookEvent.MessageUpdated
             }
         };
         var webhook = client.CreateConversationWebhook(req);
         Console.WriteLine(JsonConvert.SerializeObject(webhook));
         return(true);
     }
     catch (ErrorException e) {
         Console.WriteLine(e.ToString());
         return(false);
     }
 }