Sha256: 5da14933b6f719b0a3fc7c902f7227ca5833eac30522fc03e1a2ade1b0d9fb78

Contents?: true

Size: 927 Bytes

Versions: 11

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

require "telnyx"
require_relative "options"
require "sinatra/base"
require "json"
require "amazing_print"
require "uri"

class WebhookServer < Sinatra::Base
  set :port, 9090

  def initialize
    super
    Thread.new { telnyx_setup }
  end

  def telnyx_setup
    @fax_application = Telnyx::FaxApplication.retrieve CONFIG.fax_app_id
    @fax_application.webhook_event_url = CONFIG.webhook_url
    @fax_application.save

    puts "## Fax Send Request ##"
    ap @sent_fax = Telnyx::Fax.create(
      connection_id: CONFIG["outbound_connection_id"],
      media_url: CONFIG.document_url,
      to: CONFIG.to,
      from: CONFIG.from,
      outbound_voice_profile_id: CONFIG.outbound_voice_profile_id
    )
  end

  # Receive webhooks
  post "/*" do
    hook = JSON.parse(request.body.read, symbolize_names: true)
    puts "## Received Webhook ##"
    ap hook
    200
  end
end

WebhookServer.run!

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
telnyx-3.0.5 examples/fax/fax.rb
telnyx-3.0.4 examples/fax/fax.rb
telnyx-3.0.3 examples/fax/fax.rb
telnyx-3.0.2 examples/fax/fax.rb
telnyx-3.0.0 examples/fax/fax.rb
telnyx-2.9.0 examples/fax/fax.rb
telnyx-2.8.0 examples/fax/fax.rb
telnyx-2.7.0 examples/fax/fax.rb
telnyx-2.6.0 examples/fax/fax.rb
telnyx-2.5.0 examples/fax/fax.rb
telnyx-2.4.0 examples/fax/fax.rb