chore: Provider API prototype (#3112)
Enabling Support for Whatsapp via 360Dialog as a prototype for the provider APIs. Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -8,11 +8,7 @@ class SendReplyJob < ApplicationJob
|
||||
|
||||
case channel_name
|
||||
when 'Channel::FacebookPage'
|
||||
if conversation.additional_attributes['type'] == 'instagram_direct_message'
|
||||
::Instagram::SendOnInstagramService.new(message: message).perform
|
||||
else
|
||||
::Facebook::SendOnFacebookService.new(message: message).perform
|
||||
end
|
||||
send_on_facebook_page(message)
|
||||
when 'Channel::TwitterProfile'
|
||||
::Twitter::SendOnTwitterService.new(message: message).perform
|
||||
when 'Channel::TwilioSms'
|
||||
@@ -21,6 +17,18 @@ class SendReplyJob < ApplicationJob
|
||||
::Line::SendOnLineService.new(message: message).perform
|
||||
when 'Channel::Telegram'
|
||||
::Telegram::SendOnTelegramService.new(message: message).perform
|
||||
when 'Channel::Whatsapp'
|
||||
::Whatsapp::SendOnWhatsappService.new(message: message).perform
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send_on_facebook_page(message)
|
||||
if message.conversation.additional_attributes['type'] == 'instagram_direct_message'
|
||||
::Instagram::SendOnInstagramService.new(message: message).perform
|
||||
else
|
||||
::Facebook::SendOnFacebookService.new(message: message).perform
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
13
app/jobs/webhooks/whatsapp_events_job.rb
Normal file
13
app/jobs/webhooks/whatsapp_events_job.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Webhooks::WhatsappEventsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(params = {})
|
||||
return unless params[:phone_number]
|
||||
|
||||
channel = Channel::Whatsapp.find_by(phone_number: params[:phone_number])
|
||||
return unless channel
|
||||
|
||||
# TODO: pass to appropriate provider service from here
|
||||
Whatsapp::IncomingMessageService.new(inbox: channel.inbox, params: params['whatsapp'].with_indifferent_access).perform
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user