Module: Webhookdb::Signalwire

Includes:
Appydays::Configurable, Appydays::Loggable
Defined in:
lib/webhookdb/signalwire.rb

Class Method Summary collapse

Class Method Details

.http_request(method, tail, space_url:, project_id:, api_key:, logger:, headers: {}, body: nil, **kw) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webhookdb/signalwire.rb', line 34

def self.http_request(method, tail, space_url:, project_id:, api_key:, logger:, headers: {}, body: nil, **kw)
  url = "https://#{space_url}.signalwire.com" + tail
  headers["Content-Type"] = "application/x-www-form-urlencoded"
  headers["Accept"] = "application/json"
  kw[:body] = URI.encode_www_form(body) if body
  resp = Webhookdb::Http.send(
    method,
    url,
    basic_auth: {
      username: project_id,
      password: api_key,
    },
    logger:,
    timeout: self.http_timeout,
    headers:,
    **kw,
  )
  return resp.parsed_response
end

.send_sms(from:, to:, body:, project_id:, **kw) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/webhookdb/signalwire.rb', line 15

def self.send_sms(from:, to:, body:, project_id:, **kw)
  sms_allowed = self.sms_allowlist.any? { |pattern| File.fnmatch(pattern, to) }
  unless sms_allowed
    self.logger.warn("signalwire_sms_not_allowed", to:)
    return {"sid" => "skipped"}
  end
  return self.http_request(
    :post,
    "/2010-04-01/Accounts/#{project_id}/Messages.json",
    body: {
      From: from,
      To: to,
      Body: body,
    },
    project_id:,
    **kw,
  )
end