Chatwoot/lib/webhooks/twitter.rb
Tejaswini Chile 9984edd3ef
Feat: Manage conversation for tweets based on the tweet flag (#3353)
Add tweet conversation only if tweets are enabled.

Fixes #1961
2021-12-16 00:24:50 +05:30

30 lines
636 B
Ruby

# frozen_string_literal: true
class Webhooks::Twitter
SUPPORTED_EVENTS = [:direct_message_events, :tweet_create_events].freeze
EDITABLE_ATTRS = [:tweets_enabled].freeze
attr_accessor :params, :account
def initialize(params)
@params = params
end
def consume
send(event_name) if event_name
end
private
def event_name
@event_name ||= SUPPORTED_EVENTS.find { |key| @params.key?(key.to_s) }
end
def direct_message_events
::Twitter::DirectMessageParserService.new(payload: @params).perform
end
def tweet_create_events
::Twitter::TweetParserService.new(payload: @params).perform
end
end