Adding copilot IVA requests to posting
This commit is contained in:
parent
0bc527e78c
commit
c6bb4719f7
17
copilot/posting/README.md
Normal file
17
copilot/posting/README.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Copilot Event Requests
|
||||
|
||||
## Usage
|
||||
|
||||
The requests use the [Posting](https://posting.sh/) TUI to run requests.
|
||||
Open using the following command:
|
||||
|
||||
```bash
|
||||
posting --collection copilotux --env int.env
|
||||
```
|
||||
|
||||
You should run the **Authentication** request to obtain an API access_token
|
||||
before using the other requests.
|
||||
|
||||
## Environment
|
||||
|
||||
copy and update (/example.env) with client_id and client_secret details.
|
||||
19
copilot/posting/copilotux/IVA/authentication.posting.yaml
Normal file
19
copilot/posting/copilotux/IVA/authentication.posting.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
name: Authentication
|
||||
method: POST
|
||||
url: $TOKEN_URL
|
||||
body:
|
||||
form_data:
|
||||
- name: grant_type
|
||||
value: client_credentials
|
||||
- name: audience
|
||||
value: api://vcp/wa-cloudevent
|
||||
- name: client_id
|
||||
value: $CLIENT_ID_V2
|
||||
- name: client_secret
|
||||
value: $CLIENT_SECRET_V2
|
||||
content_type: application/x-www-form-urlencoded
|
||||
headers:
|
||||
- name: content-type
|
||||
value: application/x-www-form-urlencoded
|
||||
scripts:
|
||||
on_response: authorization.py
|
||||
@ -25,10 +25,13 @@ body:
|
||||
}
|
||||
}
|
||||
content_type: application/json
|
||||
auth:
|
||||
type: bearer_token
|
||||
bearer_token:
|
||||
token: $access_token
|
||||
headers:
|
||||
- name: Authorization
|
||||
value: Bearer $auth_token
|
||||
- name: content-type
|
||||
value: application/json
|
||||
scripts:
|
||||
setup: cloud-events.py
|
||||
on_request: cloud-events.py
|
||||
47
copilot/posting/copilotux/IVA/text-markdown.posting.yaml
Normal file
47
copilot/posting/copilotux/IVA/text-markdown.posting.yaml
Normal file
@ -0,0 +1,47 @@
|
||||
name: Text (markdown)
|
||||
method: POST
|
||||
url: $BASE_URL/v1/cloud-event
|
||||
body:
|
||||
content: |-
|
||||
{
|
||||
"customerId": "$CUSTOMER_ID",
|
||||
"source": "//iva/us-east-prd/int/demo/markdown",
|
||||
"id": "2025051416334592900000000000000001",
|
||||
"type": "verint.ui_messages.text.v1",
|
||||
"time": "2025-05-14T16:33:45.929Z",
|
||||
"upn": "$UPN",
|
||||
"userUUID": "$USER_UUID",
|
||||
"data": {
|
||||
"version": "1.0.0",
|
||||
"format": "markdown",
|
||||
"persona_icon": {
|
||||
"id": "Verint-Bot-Head",
|
||||
"color": "#007ACC"
|
||||
},
|
||||
"title_icon": {
|
||||
"id": "message-status-info",
|
||||
"color": "#FF5722"
|
||||
},
|
||||
"title": "Welcome to Customer Support",
|
||||
"body": "Hello! I'm here to help you with your inquiry. Please let me know how I can assist you today.\n\n**Available Services:**\n | Month | Savings |\n| -------- | ------- |\n| January | $250 |\n| February | $80 |\n| March | $420 |\n",
|
||||
"footer": "Need immediate assistance? Call us at 1-800-SUPPORT",
|
||||
"links_title": "Helpful Resources",
|
||||
"links": [
|
||||
{
|
||||
"text": "Visit our FAQ",
|
||||
"url": "https://support.example.com/faq"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
content_type: application/json
|
||||
auth:
|
||||
type: bearer_token
|
||||
bearer_token:
|
||||
token: $access_token
|
||||
headers:
|
||||
- name: content-type
|
||||
value: application/json
|
||||
scripts:
|
||||
setup: cloud-events.py
|
||||
on_request: cloud-events.py
|
||||
61
copilot/posting/copilotux/IVA/text-plain.posting.yaml
Normal file
61
copilot/posting/copilotux/IVA/text-plain.posting.yaml
Normal file
@ -0,0 +1,61 @@
|
||||
name: Text (plain)
|
||||
method: POST
|
||||
url: $BASE_URL/v1/cloud-event
|
||||
body:
|
||||
content: |-
|
||||
{
|
||||
"customerId": "$CUSTOMER_ID",
|
||||
"source": "//iva/us-east-prd/int/demo/plain",
|
||||
"id": "2025051416334592900000000000000001",
|
||||
"type": "verint.ui_messages.text.v1",
|
||||
"time": "2025-05-14T16:33:45.929Z",
|
||||
"upn": "$UPN",
|
||||
"userUUID": "$USER_UUID",
|
||||
"data": {
|
||||
"version": "1.0.0",
|
||||
"format": "plain",
|
||||
"persona_icon": {
|
||||
"id": "CoPilot",
|
||||
"color": "#763623"
|
||||
},
|
||||
"title_icon": {
|
||||
"id": "message-status-info",
|
||||
"color": "#763623"
|
||||
},
|
||||
"title": "Welcome to Customer Support",
|
||||
"body": "Hello! I'm here to help you with your inquiry. Please let me know how I can assist you today.\n\n**Available Services:**\n- Account Information\n- Technical Support\n- Billing Questions",
|
||||
"footer": "Need immediate assistance? Call us at 1-800-SUPPORT",
|
||||
"links_title": "Helpful Resources",
|
||||
"links": [
|
||||
{
|
||||
"text": "Visit our FAQ",
|
||||
"url": "https://support.example.com/faq"
|
||||
},
|
||||
{
|
||||
"text": "Contact Support",
|
||||
"url": "https://support.example.com/contact"
|
||||
},
|
||||
{
|
||||
"text": "User Guide",
|
||||
"url": "https://docs.example.com/user-guide"
|
||||
}
|
||||
],
|
||||
"actions_menu": [
|
||||
"send",
|
||||
"copy",
|
||||
"edit",
|
||||
"email"
|
||||
]
|
||||
}
|
||||
}
|
||||
content_type: application/json
|
||||
auth:
|
||||
type: bearer_token
|
||||
bearer_token:
|
||||
token: $access_token
|
||||
headers:
|
||||
- name: content-type
|
||||
value: application/json
|
||||
scripts:
|
||||
setup: cloud-events.py
|
||||
on_request: cloud-events.py
|
||||
15
copilot/posting/copilotux/authorization.py
Normal file
15
copilot/posting/copilotux/authorization.py
Normal file
@ -0,0 +1,15 @@
|
||||
from posting import Posting
|
||||
import httpx
|
||||
|
||||
|
||||
def on_response(response: httpx.Response, posting: Posting) -> None:
|
||||
# Raise an exception if the request failed
|
||||
response.raise_for_status()
|
||||
# Set a variable to be used in later requests.
|
||||
# You can write '$auth_token' in the UI and it will be substituted with
|
||||
# the value of the $auth_token variable.
|
||||
|
||||
access_token = response.json().get("access_token")
|
||||
print ("Successfully obtained access_token")
|
||||
|
||||
posting.set_variable("access_token", access_token)
|
||||
@ -1,49 +1,10 @@
|
||||
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
|
||||
import pprint
|
||||
|
||||
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)
|
||||
print("setup")
|
||||
|
||||
def on_request(request: RequestModel, posting: Posting) -> None:
|
||||
print("on_request")
|
||||
pprint.pp(request.dict())
|
||||
|
||||
8
copilot/posting/example.env
Normal file
8
copilot/posting/example.env
Normal file
@ -0,0 +1,8 @@
|
||||
BASE_URL=
|
||||
CLIENT_ID_V2=
|
||||
CLIENT_SECRET_V2=
|
||||
TOKEN_URL=
|
||||
AUDIENCE=
|
||||
CUSTOMER_ID=
|
||||
UPN=
|
||||
USER_UUID=
|
||||
Loading…
x
Reference in New Issue
Block a user