mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
This PR adds service to automate account abuse detection. Currently based on the signup name and URL, could potentially add more context such as usage analysis, message metadata etc.
33 lines
710 B
Ruby
33 lines
710 B
Ruby
class Internal::AccountAnalysis::WebsiteScraperService
|
|
def initialize(domain)
|
|
@domain = domain
|
|
end
|
|
|
|
def perform
|
|
return nil if @domain.blank?
|
|
|
|
Rails.logger.info("Scraping website: #{external_link}")
|
|
|
|
begin
|
|
response = HTTParty.get(external_link, follow_redirects: true)
|
|
response.to_s
|
|
rescue StandardError => e
|
|
Rails.logger.error("Error scraping website for domain #{@domain}: #{e.message}")
|
|
nil
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def external_link
|
|
sanitize_url(@domain)
|
|
end
|
|
|
|
def sanitize_url(domain)
|
|
url = domain
|
|
url = "https://#{domain}" unless domain.start_with?('http://', 'https://')
|
|
Rails.logger.info("Sanitized URL: #{url}")
|
|
url
|
|
end
|
|
end
|