Class: Assistant::MicrosoftAdsChangeApproval

Inherits:
Object
  • Object
show all
Includes:
Service
Defined in:
app/services/assistant/microsoft_ads_change_approval.rb

Overview

Issues and consumes one-time human approvals for Microsoft Ads mutations.
The approval is persisted on the conversation so a model cannot satisfy its
own confirmation prompt in the same turn. It is bound to the authenticated
sender, CRM account, tool, target IDs, and a canonicalized payload.

Defined Under Namespace

Classes: InvalidApproval, Result

Constant Summary collapse

METADATA_KEY =
'microsoft_ads_change_approval'
APPROVAL_TTL =
30.minutes
WRITE_TOOLS =
MicrosoftAdsChangePayload::WRITE_TOOLS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Service

#attributes_used, #build_result, call, #logger

Methods included from Service::Initializer

#initialize

Class Method Details

.consume(**attributes) ⇒ Result

Returns approval outcome with operation 'consume'.

Parameters:

  • attributes (Hash)

    approval context forwarded to #call

Options Hash (**attributes):

  • approval_code (String)

    code issued by the request step

  • payload_digest (String)

    digest of the approved payload

Returns:

  • (Result)

    approval outcome with operation 'consume'



53
# File 'app/services/assistant/microsoft_ads_change_approval.rb', line 53

def consume(**attributes) = call(**attributes, operation: 'consume')

.request(**attributes) ⇒ Result

Returns approval outcome with operation 'request'.

Parameters:

  • attributes (Hash)

    approval context forwarded to #call

Options Hash (**attributes):

  • tool_name (String)

    tool whose change needs approval

  • payload (Hash)

    proposed change payload

Returns:

  • (Result)

    approval outcome with operation 'request'



47
# File 'app/services/assistant/microsoft_ads_change_approval.rb', line 47

def request(**attributes) = call(**attributes, operation: 'request')

Instance Method Details

#callObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/services/assistant/microsoft_ads_change_approval.rb', line 56

def call
  validate_context!
  @change_payload = MicrosoftAdsChangePayload.call(tool_name:, payload:)

  case operation
  when 'request' then request_approval
  when 'consume' then consume_approval
  else raise InvalidApproval, 'Unsupported approval operation.'
  end
rescue InvalidApproval, MicrosoftAdsChangePayload::InvalidPayload => e
  failure(e.message)
end