From d36e1b52f670901ab50cafc3e302561b3686ebd2 Mon Sep 17 00:00:00 2001 From: Subin T P Date: Thu, 20 Feb 2020 16:19:42 +0530 Subject: [PATCH] Enhancement: Add event name in webhook payload (#528) * chore: Remove unwanted twitter gem * Enhancement: Add event name in webhook payload fixes #528 #516 #518 --- Gemfile | 1 - Gemfile.lock | 24 ------------------------ app/listeners/webhook_listener.rb | 2 +- spec/listeners/webhook_listener_spec.rb | 4 ++-- 4 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index 92f747d44..d2f3465e2 100644 --- a/Gemfile +++ b/Gemfile @@ -61,7 +61,6 @@ gem 'chargebee' ##--- gems for channels ---## gem 'facebook-messenger' gem 'telegram-bot-ruby' -gem 'twitter' # twitty will handle subscription of twitter account events gem 'twitty', git: 'https://github.com/chatwoot/twitty' diff --git a/Gemfile.lock b/Gemfile.lock index 9d33a59a6..9bb07458f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,7 +109,6 @@ GEM msgpack (~> 1.0) brakeman (4.7.2) browser (3.0.3) - buftok (0.2.0) builder (3.2.4) bullet (6.1.0) activesupport (>= 3.0.0) @@ -203,16 +202,9 @@ GEM signet (~> 0.12) haikunator (1.1.0) hashie (4.1.0) - http (3.3.0) - addressable (~> 2.3) - http-cookie (~> 1.0) - http-form_data (~> 2.0) - http_parser.rb (~> 0.6.0) http-accept (1.7.0) http-cookie (1.0.3) domain_name (~> 0.5) - http-form_data (2.2.0) - http_parser.rb (0.6.0) httparty (0.17.3) mime-types (~> 3.0) multi_xml (>= 0.5.2) @@ -259,8 +251,6 @@ GEM marcel (0.3.3) mimemagic (~> 0.3.2) memoist (0.16.2) - memoizable (0.4.2) - thread_safe (~> 0.3, >= 0.3.1) method_source (0.9.2) mime-types (3.3.1) mime-types-data (~> 3.2015) @@ -275,7 +265,6 @@ GEM multi_json (1.14.1) multi_xml (0.6.0) multipart-post (2.1.1) - naught (1.1.0) netrc (0.11.0) nightfury (1.0.1) nio4r (2.5.2) @@ -419,7 +408,6 @@ GEM faraday (~> 0.9) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - simple_oauth (0.3.1) simplecov (0.17.1) docile (~> 1.1) json (>= 1.8, < 3) @@ -445,17 +433,6 @@ GEM time_diff (0.3.0) activesupport i18n - twitter (6.2.0) - addressable (~> 2.3) - buftok (~> 0.2.0) - equalizer (~> 0.0.11) - http (~> 3.0) - http-form_data (~> 2.0) - http_parser.rb (~> 0.6.0) - memoizable (~> 0.4.0) - multipart-post (~> 2.0) - naught (~> 1.0) - simple_oauth (~> 0.3.0) tzinfo (1.2.6) thread_safe (~> 0.1) tzinfo-data (1.2019.3) @@ -556,7 +533,6 @@ DEPENDENCIES spring-watcher-listen telegram-bot-ruby time_diff - twitter twitty! tzinfo-data uglifier diff --git a/app/listeners/webhook_listener.rb b/app/listeners/webhook_listener.rb index 8b7c21934..4b370404f 100644 --- a/app/listeners/webhook_listener.rb +++ b/app/listeners/webhook_listener.rb @@ -6,7 +6,7 @@ class WebhookListener < BaseListener return unless message.reportable? && inbox.webhook.present? webhook = message.inbox.webhook - payload = message.push_event_data + payload = message.push_event_data.merge(event: __method__.to_s) webhook.urls.each do |url| WebhookJob.perform_later(url, payload) diff --git a/spec/listeners/webhook_listener_spec.rb b/spec/listeners/webhook_listener_spec.rb index e65497006..6c29c5fdf 100644 --- a/spec/listeners/webhook_listener_spec.rb +++ b/spec/listeners/webhook_listener_spec.rb @@ -24,8 +24,8 @@ describe WebhookListener do context 'when webhook is configured' do it 'triggers webhook' do - create(:webhook, inbox: inbox, account: account) - expect(WebhookJob).to receive(:perform_later).once + webhook = create(:webhook, inbox: inbox, account: account) + expect(WebhookJob).to receive(:perform_later).with(webhook.urls[0], message.push_event_data.merge(event: 'message_created')).once listener.message_created(event) end end