Twilio (twilio/voice_webhook_setup_service.rb)

chatwoot · enterprise/app/services/twilio/voice_webhook_setup_service.rb · ruby · MIT
voice

Sets up Twilio voice webhooks for a channel, creating or updating TwiML apps and phone number webhooks.

# Source: https://github.com/chatwoot/chatwoot | License: MIT | Copyright 2017-2026 Chatwoot Inc
# Provided via justclaw.it.com; keep this notice with the code.
class Twilio::VoiceWebhookSetupService
  include Rails.application.routes.url_helpers

  pattr_initialize [:channel!]

  HTTP_METHOD = 'POST'.freeze

  # Returns created TwiML App SID on success.
  def perform
    validate_token_credentials!

    app_sid = create_twiml_app!
    configure_number_webhooks!
    app_sid
  end

  # Outbound calls dial through the TwiML app, so its voice_url must track the current host too.
  def sync_twiml_app!
    return create_twiml_app! if channel.twiml_app_sid.blank?

    channel.client.applications(channel.twiml_app_sid).update(
      voice_url: channel.voice_call_webhook_url,
      voice_method: H

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key