mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-05 05:27:48 +00:00
# Pull Request Template ## Description Dyte V1 API's are soon going to be deprecated, hence making sure we update Chatwoot before that happens Fixes #10704 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? 1. Open a new or existing conversation from the inbox 2. Press the video call icon on the message composer 3. Verify that the message dialog shows up with the join video call button 4. Verify that clicking on join call does join the call ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] My changes generate no new warnings - [ ] New and existing unit tests pass locally with my changes (Unable to run this locally) --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
55 lines
1.4 KiB
Ruby
55 lines
1.4 KiB
Ruby
class Integrations::Dyte::ProcessorService
|
|
pattr_initialize [:account!, :conversation!]
|
|
|
|
def create_a_meeting(agent)
|
|
title = I18n.t('integration_apps.dyte.meeting_name', agent_name: agent.available_name)
|
|
response = dyte_client.create_a_meeting(title)
|
|
|
|
return response if response[:error].present?
|
|
|
|
meeting = response
|
|
message = create_a_dyte_integration_message(meeting, title, agent)
|
|
message.push_event_data
|
|
end
|
|
|
|
def add_participant_to_meeting(meeting_id, user)
|
|
dyte_client.add_participant_to_meeting(meeting_id, user.id, user.name, avatar_url(user))
|
|
end
|
|
|
|
private
|
|
|
|
def create_a_dyte_integration_message(meeting, title, agent)
|
|
@conversation.messages.create!(
|
|
{
|
|
account_id: conversation.account_id,
|
|
inbox_id: conversation.inbox_id,
|
|
message_type: :outgoing,
|
|
content_type: :integrations,
|
|
content: title,
|
|
content_attributes: {
|
|
type: 'dyte',
|
|
data: {
|
|
meeting_id: meeting['id']
|
|
}
|
|
},
|
|
sender: agent
|
|
}
|
|
)
|
|
end
|
|
|
|
def avatar_url(user)
|
|
return user.avatar_url if user.avatar_url.present?
|
|
|
|
"#{ENV.fetch('FRONTEND_URL', nil)}/integrations/slack/user.png"
|
|
end
|
|
|
|
def dyte_hook
|
|
@dyte_hook ||= account.hooks.find_by!(app_id: 'dyte')
|
|
end
|
|
|
|
def dyte_client
|
|
credentials = dyte_hook.settings
|
|
@dyte_client ||= Dyte.new(credentials['organization_id'], credentials['api_key'])
|
|
end
|
|
end
|