Adding posting.sh example for copilot cloud events
This commit is contained in:
parent
d2e9bcfa85
commit
0bc527e78c
49
copilot/posting/copilotux/cloud-events.py
Normal file
49
copilot/posting/copilotux/cloud-events.py
Normal file
@ -0,0 +1,49 @@
|
||||
from posting import Auth, Header, RequestModel, Posting
|
||||
import httpx
|
||||
|
||||
def get_oauth2_token(client_id, client_secret, token_url, audience):
|
||||
"""
|
||||
Request an OAuth2 access token using the Client Credentials Grant flow.
|
||||
|
||||
Args:
|
||||
client_id (str): The client ID provided by the OAuth2 provider.
|
||||
client_secret (str): The client secret provided by the OAuth2 provider.
|
||||
token_url (str): The URL to request the access token.
|
||||
|
||||
Returns:
|
||||
str: The access token if the request is successful.
|
||||
"""
|
||||
# Prepare the data for the token request
|
||||
data = {
|
||||
"grant_type": "client_credentials", # Grant type for Client Credentials flow
|
||||
"client_id": client_id,
|
||||
"client_secret": client_secret,
|
||||
"audience": audience
|
||||
}
|
||||
|
||||
try:
|
||||
# Make the POST request to the token endpoint
|
||||
response = httpx.post(token_url, data=data)
|
||||
|
||||
# Raise an exception if the request failed
|
||||
response.raise_for_status()
|
||||
|
||||
# Parse the JSON response
|
||||
token_data = response.json()
|
||||
|
||||
print ("Successfully obtained access_token")
|
||||
|
||||
# Return the access token
|
||||
return token_data.get("access_token")
|
||||
except httpx.RequestError as e:
|
||||
print(f"An error occurred while requesting the token: {e}")
|
||||
except httpx.HTTPStatusError as e:
|
||||
print(f"HTTP error occurred: {e.response.status_code} - {e.response.text}")
|
||||
except KeyError:
|
||||
print("The response did not contain an access token.")
|
||||
return None
|
||||
|
||||
def setup(posting: Posting) -> None:
|
||||
if not posting.get_variable("auth_token"):
|
||||
token = get_oauth2_token(posting.variables["CLIENT_ID_V2"], posting.variables["CLIENT_SECRET_V2"],posting.variables["TOKEN_URL"],posting.variables["AUDIENCE"],)
|
||||
posting.set_variable("auth_token", token)
|
||||
34
copilot/posting/copilotux/smart-transfer.posting.yaml
Normal file
34
copilot/posting/copilotux/smart-transfer.posting.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
name: Smart Transfer
|
||||
method: POST
|
||||
url: $BASE_URL/v1/cloud-event
|
||||
body:
|
||||
content: |-
|
||||
{
|
||||
"customerId": "$CUSTOMER_ID",
|
||||
"source": "//iva/us-east-prd/transfer",
|
||||
"id": "2025051416334592900000000000000001",
|
||||
"type": "iva.transfer.data.v1",
|
||||
"time": "2025-05-14T16:33:45.929Z",
|
||||
"upn": "$UPN",
|
||||
"userUUID": "$USER_UUID",
|
||||
"data": {
|
||||
"conversationId": "2025051416334592900000000000000001",
|
||||
"customData": {
|
||||
"firstName": "John",
|
||||
"lastName": "Smith",
|
||||
"phoneNumber": "9887655432",
|
||||
"accountID": "1234",
|
||||
"summary": "summary test",
|
||||
"lastContactDate": "09/09/2020",
|
||||
"purpose": "Testing Purpose"
|
||||
}
|
||||
}
|
||||
}
|
||||
content_type: application/json
|
||||
headers:
|
||||
- name: Authorization
|
||||
value: Bearer $auth_token
|
||||
- name: content-type
|
||||
value: application/json
|
||||
scripts:
|
||||
setup: cloud-events.py
|
||||
Loading…
x
Reference in New Issue
Block a user