Class: Webhookdb::Oauth::IntercomProvider

Inherits:
Provider
  • Object
show all
Includes:
Appydays::Loggable
Defined in:
lib/webhookdb/oauth/intercom_provider.rb

Instance Method Summary collapse

Instance Method Details

#app_nameObject



9
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 9

def app_name = "Intercom"

#authorization_url(state:) ⇒ Object



13
14
15
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 13

def authorization_url(state:)
  return "https://app.intercom.com/oauth?client_id=#{Webhookdb::Intercom.client_id}&state=#{state}"
end

#build_marketplace_integrations(organization:, tokens:, scope:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 45

def build_marketplace_integrations(organization:, tokens:, scope:)
  intercom_user = scope.fetch(:me_response)
  # The intercom workspace id is used in the intercom webhook endpoint to identify which
  # service integration to delegate requests to.
  intercom_workspace_id = intercom_user.dig("app", "id_code")
  root_sint = Webhookdb::ServiceIntegration.create_disambiguated(
    "intercom_marketplace_root_v1",
    organization:,
    api_url: intercom_workspace_id,
    backfill_key: tokens.access_token,
  )
  root_sint.replicator.build_dependents
end

#exchange_authorization_code(code:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 17

def exchange_authorization_code(code:)
  token_resp = Webhookdb::Http.post(
    "https://api.intercom.io/auth/eagle/token",
    {
      "client_id" => Webhookdb::Intercom.client_id,
      "client_secret" => Webhookdb::Intercom.client_secret,
      "code" => code,
    },
    logger: self.logger,
    timeout: Webhookdb::Intercom.http_timeout,
  )
  return Webhookdb::Oauth::Tokens.new(access_token: token_resp.parsed_response["token"])
end

#find_or_create_customer(tokens:, scope:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 31

def find_or_create_customer(tokens:, scope:)
  intercom_user_resp = Webhookdb::Http.get(
    "https://api.intercom.io/me",
    headers: Webhookdb::Intercom.auth_headers(tokens.access_token),
    logger: self.logger,
    timeout: Webhookdb::Intercom.http_timeout,
  )

  intercom_user = intercom_user_resp.parsed_response
  scope[:me_response] = intercom_user
  intercom_email = intercom_user.fetch("email")
  return Webhookdb::Customer.find_or_create_for_email(intercom_email)
end

#keyObject



8
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 8

def key = "intercom"

#requires_webhookdb_auth?Boolean

Returns:

  • (Boolean)


10
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 10

def requires_webhookdb_auth? = false

#supports_webhooks?Boolean

Returns:

  • (Boolean)


11
# File 'lib/webhookdb/oauth/intercom_provider.rb', line 11

def supports_webhooks? = false