From 676633a743eeab0bf599d97c23c68aebc6f5f10f Mon Sep 17 00:00:00 2001 From: vdlima <67575271+vdlima@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:02:42 -0800 Subject: [PATCH] Enable Insights API (#275) --- ...L_commands_with_SIP_TRUNK_management.ipynb | 1386 +++++++++-------- 1 file changed, 694 insertions(+), 692 deletions(-) diff --git a/tools/SIP_SIPREC_integration_Dialogflow_CURL_commands_with_SIP_TRUNK_management.ipynb b/tools/SIP_SIPREC_integration_Dialogflow_CURL_commands_with_SIP_TRUNK_management.ipynb index d3333e04..0c6dbc36 100644 --- a/tools/SIP_SIPREC_integration_Dialogflow_CURL_commands_with_SIP_TRUNK_management.ipynb +++ b/tools/SIP_SIPREC_integration_Dialogflow_CURL_commands_with_SIP_TRUNK_management.ipynb @@ -1,701 +1,703 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "A-itjGDAUFy9" - }, - "source": [ - "# README\n", - "\n", - "This notebook is designed to help you create a SIP/SIPREC integration with CCAI. You can execute this notebook in the \"Colab Enterprise\" product within the Google Cloud Console. Note that you will need to enable some additional apis/services to run Colab Enterprise.\n", - "\n", - "This notebook is divided into 4 sections :\n", - "1. Project setup :\n", - " - Specify your project details. If you are using a pre-generated JWT (from a Service Account for example) you can enter that here so that API calls are made using those credentials. We enable the Dialogflow API in the project using your credentials just in case it hasn't been done before in the UI.\n", - "\n", - "2. Configuring CCAI for SIP/SIPREC :\n", - " - Create a dummy Dialogflow ES agent and set the tier to 'Enterprise' in order to override the free 'Trial' quota that is set up by default.\n", - " - Get a Google Phone Number, create a Security Settings object, create a ConversationProfile and associate the Google Phone Number with the ConversationProfile.\n", - "\n", - "3. SIP Trunk Management :\n", - " - Create a SIP TRUNK with your SBCs Fully Qualified Domain Names (FQDNs) as containted in the certificates used for authentication.\n", - " - Other methods to manage the SIP TRUNKs.\n", - "\n", - "4. Utility functions :\n", - " - Get and List methods to view resources created.\n", - " - Delete method to delete resources created." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "nSAtlvmuagBQ" - }, - "source": [ - "# Project setup" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "executionInfo": { - "elapsed": 3008, - "status": "ok", - "timestamp": 1728504494188, - "user": { - "displayName": "", - "userId": "" - }, - "user_tz": 420 - }, - "id": "BDe-MhXg2U7C" - }, - "outputs": [], - "source": [ - "import json\n", - "import os\n", - "import re\n", - "import sys\n", - "\n", - "\n", - "PROJECT_ID = !gcloud config get-value project\n", - "PROJECT_ID = PROJECT_ID[0]\n", - "REGION = \"ccai-region\" # @param {type:\"string\"}\n", - "JWT = \"Leave as-is to use SSO or enter generated JWT token here\" # @param {type:\"string\"}\n", - "\n", - "# Ensure that the project has Dialogflow APIs enabled\n", - "!gcloud services enable dialogflow.googleapis.com\n", - "\n", - "CONTAINS_SPACES_PATTERN = r\"\\s\"\n", - "# If the JWT string has spaces, then use SSO for authentication\n", - "if re.search(CONTAINS_SPACES_PATTERN, JWT):\n", - " JWT = !gcloud auth print-access-token\n", - " JWT = JWT[0]\n", - "\n", - "if REGION == \"global\":\n", - " LOCATION_ID = \"\"\n", - "else:\n", - " LOCATION_ID = REGION + \"-\"" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "o5wTWF_HowQf" - }, - "source": [ - "# Configuring CCAI for SIP/SIPREC" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "UmNL7NISdGgp" - }, - "outputs": [], - "source": [ - "# @title Create a dummy Dialogflow ES agent and set the tier to Enterprise in order to remove the Trial quota limits and permit making additional quota requests\n", - "\n", - "create_dummy_agent = f\"\"\"\n", - "curl -X POST \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "-d '{{\n", - " \"displayName\": \"Dummy_ES_agent\",\n", - " \"timeZone\": \"America/Los_Angeles\",\n", - " \"tier\": \"TIER_ENTERPRISE\"\n", - " }}' \\\n", - "https://dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/global/agent\n", - "\"\"\"\n", - "\n", - "request = os.popen(create_dummy_agent).read()\n", - "\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "s2lzeQoq3i3X" - }, - "outputs": [], - "source": [ - "# @title Script to create a ConversationProfile with GTP integration and export to Insights enabled\n", - "\n", - "CONVERSATION_PROFILE_NAME = \"GTP integration with export to Insights\" # @param {type:\"string\"}\n", - "SECURITY_SETTINGS_NAME = \"Export to Insights ONLY\" # @param {type:\"string\"}\n", - "PHONE_NUMBER_COUNTRY_CODE = 1 # @param {type:\"number\"}\n", - "CX_AGENT_NAME = \"CX agent name\" # @param {type:\"string\"}\n", - "\n", - "\n", - "AGENT_NAME_PATTERN = r\"^projects/([^/]+)/locations/([^/]+)/agents/([^/]+)\"\n", - "if re.search(AGENT_NAME_PATTERN, CX_AGENT_NAME):\n", - " print(\"Dialogflow CX agent name provided.\")\n", - " virtual_agent = True\n", - "else:\n", - " print(\"No Dialogflow CX agent name provided.\")\n", - " virtual_agent = False\n", - "\n", - "project_allowlisted = True\n", - "\n", - "# Create PhoneNumberOrder\n", - "\n", - "print(\"\\nCreating Phone Number Order Object:\\n\")\n", - "create_phone_number_order = f\"\"\"\n", - "curl -X POST \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "-d '{{\n", - " \"phoneNumberSpec\": {{\n", - " \"countryCode\": {PHONE_NUMBER_COUNTRY_CODE},\n", - " \"count\": 1\n", - " }}\n", - " }}' \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/phoneNumberOrders\n", - "\"\"\"\n", - "\n", - "request = os.popen(create_phone_number_order).read()\n", - "\n", - "if isinstance(request, str):\n", - " phone_number_order_response = json.loads(request)\n", - " phone_number_name = list(phone_number_order_response[\"phoneNumbers\"].keys())[0]\n", - " print(\"Phone number name: \" + phone_number_name)\n", - "else:\n", - " print(f'\\n>>>> PROJECT \"{PROJECT_ID}\" HAS NOT BEEN ALLOWLISTED. <<<< \\n\\n\\n'\n", - " 'Submit the form https://docs.google.com/forms/d/e/1FAIpQLSe2xMdpg_L2bhvl4EoNTUC4Nctzc3Qlw54uQ1_JNFgr0VhOfg/viewform '\n", - " 'wait to hear back and then re-run this script.\\n\\n')\n", - " project_allowlisted = False\n", - "\n", - "if project_allowlisted:\n", - "\n", - " # Create Security Settings object\n", - "\n", - " print(\"\\nCreating Security Settings Object:\\n\")\n", - " create_security_settings_obj = f\"\"\"\n", - " curl -X POST \\\n", - " -H \"Authorization: Bearer {JWT}\" \\\n", - " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - " -H \"Content-Type: application/json; charset=utf-8\" \\\n", - " -d '{{\n", - " \"displayName\": \"{SECURITY_SETTINGS_NAME}\",\n", - " \"insightsExportSettings\": {{\n", - " \"enableInsightsExport\": true\n", - " }}\n", - " }}' \\\n", - " https://{LOCATION_ID}dialogflow.googleapis.com/v3/projects/{PROJECT_ID}/locations/{REGION}/securitySettings\n", - " \"\"\"\n", - "\n", - " security_settings_response = json.loads(os.popen(create_security_settings_obj).read())\n", - " security_settings_name = security_settings_response[\"name\"]\n", - " print(\"Security settings name: \" + security_settings_name)\n", - "\n", - " # Create ConversationProfile\n", - "\n", - " if virtual_agent:\n", - " print(\"\\nCreating Conversation Profile object with CX virtual agent and Insights support:\\n\")\n", - " create_siprec_conversation_profile_obj = f\"\"\"\n", - " curl -X POST \\\n", - " -H \"Authorization: Bearer {JWT}\" \\\n", - " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - " -H \"Content-Type: application/json; charset=utf-8\" \\\n", - " -d '{{\n", - " \"displayName\": \"{CONVERSATION_PROFILE_NAME}\",\n", - " \"languageCode\": \"en-US\",\n", - " \"automatedAgentConfig\": {{\n", - " \"agent\": \"{CX_AGENT_NAME}\"\n", - " }},\n", - " \"sipConfig\": {{\n", - " \"createConversationOnTheFly\": true,\n", - " \"allowVirtualAgentInteraction\": true\n", - " }},\n", - " \"securitySettings\": \"{security_settings_name}\"\n", - " }}' \\\n", - " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", - " \"\"\"\n", - "\n", - " else:\n", - " print(\"\\nCreating Conversation Profile object with transcription and Insights support.:\\n\")\n", - " create_siprec_conversation_profile_obj = f\"\"\"\n", - " curl -X POST \\\n", - " -H \"Authorization: Bearer {JWT}\" \\\n", - " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - " -H \"Content-Type: application/json; charset=utf-8\" \\\n", - " -d '{{\n", - " \"displayName\": \"{CONVERSATION_PROFILE_NAME}\",\n", - " \"languageCode\": \"en-US\",\n", - " \"sipConfig\": {{\n", - " \"createConversationOnTheFly\": true\n", - " }},\n", - " \"securitySettings\": \"{security_settings_name}\"\n", - " }}' \\\n", - " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", - " \"\"\"\n", - "\n", - " siprec_conversation_profile_response = json.loads(os.popen(create_siprec_conversation_profile_obj).read())\n", - " conversation_profile_obj_name = siprec_conversation_profile_response[\"name\"]\n", - " print(\"Conversation profile name: \" + conversation_profile_obj_name)\n", - "\n", - " # Associate PhoneNumber with ConversationProfile\n", - "\n", - " print(\"\\nAssociating Phone Number with Conversation Profile:\\n\")\n", - " associate_phone_number_with_conv_profile = f\"\"\"\n", - " curl -X PATCH \\\n", - " -H \"Authorization: Bearer {JWT}\" \\\n", - " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - " -H \"Content-Type: application/json; charset=utf-8\" \\\n", - " -d '{{\n", - " \"conversationProfile\": \"{conversation_profile_obj_name}\"\n", - " }}' \\\n", - " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{phone_number_name}?update_mask=conversationProfile\n", - " \"\"\"\n", - "\n", - " response = json.loads(os.popen(associate_phone_number_with_conv_profile).read())\n", - " print(response)\n", - "\n", - "print(\"\\nDone!\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ZVWKweSromS1" - }, - "source": [ - "# SIP Trunk Creation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "bDz5RHChPzKK" - }, - "outputs": [], - "source": [ - "# @title CreateSipTrunk\n", - "\n", - "HOSTNAMES = [\"host.na.me1\", \"host.na.me2\"] # @param\n", - "DISPLAY_NAME = \"sip_trunk_name\" # @param {type:\"string\"}\n", - "\n", - "\n", - "hostname_expression = \"\"\n", - "for host in HOSTNAMES:\n", - " hostname_expression += f'\"expected_hostname\": \"{host}\",'\n", - "\n", - "curl = f\"\"\"\n", - "curl -X POST \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "-d '{{\n", - " {hostname_expression}\n", - " \"display_name\": \"{DISPLAY_NAME}\"\n", - " }}' \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/sipTrunks\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "TYmxJhBo2RDm" - }, - "source": [ - "# Utility functions (List/Get/Delete methods for resources created)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "1xPq_CC72bPq" - }, - "outputs": [], - "source": [ - "# @title View ConversationProfile and PhoneNumber details\n", - "\n", - "conversation_profiles_dict = {}\n", - "orphan_phone_numbers = []\n", - "\n", - "# Get all the ConversationProfiles and see which ones have sipConfig configured\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, str):\n", - " response = json.loads(request)\n", - "\n", - " for data in response[\"conversationProfiles\"]:\n", - " conversation_profile_name = data[\"name\"]\n", - " conversation_profiles_dict[conversation_profile_name] = {}\n", - " # print(data)\n", - " if \"sipConfig\" in data:\n", - " conversation_profiles_dict[conversation_profile_name][\"sipConfig\"] = data[\"sipConfig\"]\n", - " if \"automatedAgentConfig\" in data:\n", - " conversation_profiles_dict[conversation_profile_name][\"automatedAgentConfig\"] = data[\"automatedAgentConfig\"]\n", - "\n", - "# Get all phone numbers and see which ones are associated with a ConversationProfile\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/phoneNumbers\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, str):\n", - " response = json.loads(request)\n", - "\n", - " if \"phoneNumbers\" in response:\n", - " for data in response[\"phoneNumbers\"]:\n", - " phone_number = data[\"phoneNumber\"]\n", - " if \"conversationProfile\" in data:\n", - " conversation_profile_name = data[\"conversationProfile\"]\n", - " conversation_profiles_dict[conversation_profile_name][\"phone_number\"] = phone_number\n", - " else:\n", - " orphan_phone_numbers.append(phone_number)\n", - "\n", - " if orphan_phone_numbers:\n", - " print(f\"There is/are {len(orphan_phone_numbers)} phone numbers not associated with a ConversationProfile:\\n {orphan_phone_numbers}\\n\\n\")\n", - "\n", - " for conversation_profile_name, details in conversation_profiles_dict.items():\n", - " print(f\"Conversation Profile: {conversation_profile_name}\")\n", - " if details:\n", - " if \"sipConfig\" in details and details[\"sipConfig\"]:\n", - " print(f\"SipConfig is set: {details['sipConfig']}\")\n", - " if \"automatedAgentConfig\" in details:\n", - " print(f\"Virtual agent is configured: {details['automatedAgentConfig']}\")\n", - " if \"phone_number\" in details:\n", - " print(f\"Phone number is associated: {details['phone_number']}\")\n", - " print(\"\\n\")\n", - " else:\n", - " print(\"No phone numbers present\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "eLSdPEMWcGhf" - }, - "outputs": [], - "source": [ - "# @title GetConversation\n", - "\n", - "conversation_name = \"projects//locations//conversations/\" # @param {type:\"string\"}\n", - "\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{conversation_name}\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "W-wa4CZGwVJL" - }, - "outputs": [], - "source": [ - "# @title ListSecuritySettings\n", - "\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v3/projects/{PROJECT_ID}/locations/{REGION}/securitySettings\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "s7MfoE_IRyce" - }, - "outputs": [], - "source": [ - "# @title ListConversationProfiles\n", - "\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "jcL-Vtz5evzX" - }, - "outputs": [], - "source": [ - "# @title ListPhoneNumbers\n", - "\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/phoneNumbers\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": { - "executionInfo": { - "elapsed": 10, - "status": "ok", - "timestamp": 1728507630448, - "user": { - "displayName": "", - "userId": "" - }, - "user_tz": 420 - }, - "id": "y6UmqCDL6UB_" - }, - "outputs": [], - "source": [ - "# @title Delete resource objects\n", - "\n", - "resource_name = \"projects//locations///\" # @param {type:\"string\"}\n", - "\n", - "security_settings_name = \"\"\n", - "conversation_profile_name = \"\"\n", - "phone_number_name = \"\"\n", - "\n", - "\n", - "security_settings_pattern = \"^projects/([^/]+)/locations/([^/]+)/securitySettings/([^/]+)\"\n", - "# Security settings uses the v3alpha1 api\n", - "if re.search(security_settings_pattern, resource_name):\n", - " print(\"Deleting Security Settings object: \" + resource_name)\n", - " curl = f\"\"\"\n", - " curl -X DELETE \\\n", - " -H \"Authorization: Bearer {JWT}\" \\\n", - " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - " -H \"Content-Type: application/json; charset=utf-8\" \\\n", - " https://{LOCATION_ID}dialogflow.googleapis.com/v3alpha1/{resource_name}\n", - " \"\"\"\n", - " response = json.loads(os.popen(curl).read())\n", - " print(response)\n", - "\n", - "conversation_profile_pattern = \"^projects/([^/]+)/locations/([^/]+)/conversationProfiles/([^/]+)\"\n", - "phone_number_pattern = \"^projects/([^/]+)/locations/([^/]+)/phoneNumbers/([^/]+)\"\n", - "\n", - "# ConversationProfile and PhoneNumbers use the v2beta1 api\n", - "if (re.search(conversation_profile_pattern, resource_name) or\n", - " re.search(phone_number_pattern, resource_name)):\n", - " print(\"Deleting object: \" + resource_name)\n", - " curl = f\"\"\"\n", - " curl -X DELETE \\\n", - " -H \"Authorization: Bearer {JWT}\" \\\n", - " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - " -H \"Content-Type: application/json; charset=utf-8\" \\\n", - " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{resource_name}\n", - " \"\"\"\n", - " response = json.loads(os.popen(curl).read())\n", - " print(response)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "wreAsBY3L3Lk" - }, - "outputs": [], - "source": [ - "# @title ListSipTrunks\n", - "\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/sipTrunks\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "A-itjGDAUFy9" + }, + "source": [ + "# README\n", + "\n", + "This notebook is designed to help you create a SIP/SIPREC integration with CCAI. You can execute this notebook in the \"Colab Enterprise\" product within the Google Cloud Console. Note that you will need to enable some additional apis/services to run Colab Enterprise.\n", + "\n", + "This notebook is divided into 4 sections :\n", + "1. Project setup :\n", + " - Specify your project details. If you are using a pre-generated JWT (from a Service Account for example) you can enter that here so that API calls are made using those credentials. We enable the Dialogflow API in the project using your credentials just in case it hasn't been done before in the UI.\n", + "\n", + "2. Configuring CCAI for SIP/SIPREC :\n", + " - Create a dummy Dialogflow ES agent and set the tier to 'Enterprise' in order to override the free 'Trial' quota that is set up by default.\n", + " - Get a Google Phone Number, create a Security Settings object, create a ConversationProfile and associate the Google Phone Number with the ConversationProfile.\n", + "\n", + "3. SIP Trunk Management :\n", + " - Create a SIP TRUNK with your SBCs Fully Qualified Domain Names (FQDNs) as containted in the certificates used for authentication.\n", + " - Other methods to manage the SIP TRUNKs.\n", + "\n", + "4. Utility functions :\n", + " - Get and List methods to view resources created.\n", + " - Delete method to delete resources created." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nSAtlvmuagBQ" + }, + "source": [ + "# Project setup" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "executionInfo": { + "elapsed": 3008, + "status": "ok", + "timestamp": 1728504494188, + "user": { + "displayName": "", + "userId": "" + }, + "user_tz": 420 }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "cellView": "form", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "executionInfo": { - "elapsed": 6, - "status": "ok", - "timestamp": 1728507630448, - "user": { - "displayName": "", - "userId": "" - }, - "user_tz": 420 - }, - "id": "L9ixrCWimlqB", - "outputId": "7a0ae3ea-61e7-4068-fe84-b4f8724c1cff" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], - "source": [ - "# @title GetSipTrunk\n", - "\n", - "RESOURCE_NAME = \"projects//locations//sipTrunks/\" # @param {type:\"string\"}\n", - "# eg. value projects/project_name/locations/global/sipTrunks/JxN1ndLCR9OJvgrDlc32_Q\n", - "\n", - "curl = f\"\"\"\n", - "curl -X GET \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{RESOURCE_NAME}\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] + "id": "BDe-MhXg2U7C" + }, + "outputs": [], + "source": [ + "import json\n", + "import os\n", + "import re\n", + "import sys\n", + "\n", + "\n", + "PROJECT_ID = !gcloud config get-value project\n", + "PROJECT_ID = PROJECT_ID[0]\n", + "REGION = \"ccai-region\" # @param {type:\"string\"}\n", + "JWT = \"Leave as-is to use SSO or enter generated JWT token here\" # @param {type:\"string\"}\n", + "\n", + "# Ensure that the project has Dialogflow APIs enabled\n", + "!gcloud services enable dialogflow.googleapis.com\n", + "# Ensure that the project has Insights APIs enabled\n", + "!gcloud services enable contactcenterinsights.com\n", + "\n", + "CONTAINS_SPACES_PATTERN = r\"\\s\"\n", + "# If the JWT string has spaces, then use SSO for authentication\n", + "if re.search(CONTAINS_SPACES_PATTERN, JWT):\n", + " JWT = !gcloud auth print-access-token\n", + " JWT = JWT[0]\n", + "\n", + "if REGION == \"global\":\n", + " LOCATION_ID = \"\"\n", + "else:\n", + " LOCATION_ID = REGION + \"-\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o5wTWF_HowQf" + }, + "source": [ + "# Configuring CCAI for SIP/SIPREC" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "UmNL7NISdGgp" + }, + "outputs": [], + "source": [ + "# @title Create a dummy Dialogflow ES agent and set the tier to Enterprise in order to remove the Trial quota limits and permit making additional quota requests\n", + "\n", + "create_dummy_agent = f\"\"\"\n", + "curl -X POST \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "-d '{{\n", + " \"displayName\": \"Dummy_ES_agent\",\n", + " \"timeZone\": \"America/Los_Angeles\",\n", + " \"tier\": \"TIER_ENTERPRISE\"\n", + " }}' \\\n", + "https://dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/global/agent\n", + "\"\"\"\n", + "\n", + "request = os.popen(create_dummy_agent).read()\n", + "\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "s2lzeQoq3i3X" + }, + "outputs": [], + "source": [ + "# @title Script to create a ConversationProfile with GTP integration and export to Insights enabled\n", + "\n", + "CONVERSATION_PROFILE_NAME = \"GTP integration with export to Insights\" # @param {type:\"string\"}\n", + "SECURITY_SETTINGS_NAME = \"Export to Insights ONLY\" # @param {type:\"string\"}\n", + "PHONE_NUMBER_COUNTRY_CODE = 1 # @param {type:\"number\"}\n", + "CX_AGENT_NAME = \"CX agent name\" # @param {type:\"string\"}\n", + "\n", + "\n", + "AGENT_NAME_PATTERN = r\"^projects/([^/]+)/locations/([^/]+)/agents/([^/]+)\"\n", + "if re.search(AGENT_NAME_PATTERN, CX_AGENT_NAME):\n", + " print(\"Dialogflow CX agent name provided.\")\n", + " virtual_agent = True\n", + "else:\n", + " print(\"No Dialogflow CX agent name provided.\")\n", + " virtual_agent = False\n", + "\n", + "project_allowlisted = True\n", + "\n", + "# Create PhoneNumberOrder\n", + "\n", + "print(\"\\nCreating Phone Number Order Object:\\n\")\n", + "create_phone_number_order = f\"\"\"\n", + "curl -X POST \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "-d '{{\n", + " \"phoneNumberSpec\": {{\n", + " \"countryCode\": {PHONE_NUMBER_COUNTRY_CODE},\n", + " \"count\": 1\n", + " }}\n", + " }}' \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/phoneNumberOrders\n", + "\"\"\"\n", + "\n", + "request = os.popen(create_phone_number_order).read()\n", + "\n", + "if isinstance(request, str):\n", + " phone_number_order_response = json.loads(request)\n", + " phone_number_name = list(phone_number_order_response[\"phoneNumbers\"].keys())[0]\n", + " print(\"Phone number name: \" + phone_number_name)\n", + "else:\n", + " print(f'\\n>>>> PROJECT \"{PROJECT_ID}\" HAS NOT BEEN ALLOWLISTED. <<<< \\n\\n\\n'\n", + " 'Submit the form https://docs.google.com/forms/d/e/1FAIpQLSe2xMdpg_L2bhvl4EoNTUC4Nctzc3Qlw54uQ1_JNFgr0VhOfg/viewform '\n", + " 'wait to hear back and then re-run this script.\\n\\n')\n", + " project_allowlisted = False\n", + "\n", + "if project_allowlisted:\n", + "\n", + " # Create Security Settings object\n", + "\n", + " print(\"\\nCreating Security Settings Object:\\n\")\n", + " create_security_settings_obj = f\"\"\"\n", + " curl -X POST \\\n", + " -H \"Authorization: Bearer {JWT}\" \\\n", + " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + " -H \"Content-Type: application/json; charset=utf-8\" \\\n", + " -d '{{\n", + " \"displayName\": \"{SECURITY_SETTINGS_NAME}\",\n", + " \"insightsExportSettings\": {{\n", + " \"enableInsightsExport\": true\n", + " }}\n", + " }}' \\\n", + " https://{LOCATION_ID}dialogflow.googleapis.com/v3/projects/{PROJECT_ID}/locations/{REGION}/securitySettings\n", + " \"\"\"\n", + "\n", + " security_settings_response = json.loads(os.popen(create_security_settings_obj).read())\n", + " security_settings_name = security_settings_response[\"name\"]\n", + " print(\"Security settings name: \" + security_settings_name)\n", + "\n", + " # Create ConversationProfile\n", + "\n", + " if virtual_agent:\n", + " print(\"\\nCreating Conversation Profile object with CX virtual agent and Insights support:\\n\")\n", + " create_siprec_conversation_profile_obj = f\"\"\"\n", + " curl -X POST \\\n", + " -H \"Authorization: Bearer {JWT}\" \\\n", + " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + " -H \"Content-Type: application/json; charset=utf-8\" \\\n", + " -d '{{\n", + " \"displayName\": \"{CONVERSATION_PROFILE_NAME}\",\n", + " \"languageCode\": \"en-US\",\n", + " \"automatedAgentConfig\": {{\n", + " \"agent\": \"{CX_AGENT_NAME}\"\n", + " }},\n", + " \"sipConfig\": {{\n", + " \"createConversationOnTheFly\": true,\n", + " \"allowVirtualAgentInteraction\": true\n", + " }},\n", + " \"securitySettings\": \"{security_settings_name}\"\n", + " }}' \\\n", + " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", + " \"\"\"\n", + "\n", + " else:\n", + " print(\"\\nCreating Conversation Profile object with transcription and Insights support.:\\n\")\n", + " create_siprec_conversation_profile_obj = f\"\"\"\n", + " curl -X POST \\\n", + " -H \"Authorization: Bearer {JWT}\" \\\n", + " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + " -H \"Content-Type: application/json; charset=utf-8\" \\\n", + " -d '{{\n", + " \"displayName\": \"{CONVERSATION_PROFILE_NAME}\",\n", + " \"languageCode\": \"en-US\",\n", + " \"sipConfig\": {{\n", + " \"createConversationOnTheFly\": true\n", + " }},\n", + " \"securitySettings\": \"{security_settings_name}\"\n", + " }}' \\\n", + " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", + " \"\"\"\n", + "\n", + " siprec_conversation_profile_response = json.loads(os.popen(create_siprec_conversation_profile_obj).read())\n", + " conversation_profile_obj_name = siprec_conversation_profile_response[\"name\"]\n", + " print(\"Conversation profile name: \" + conversation_profile_obj_name)\n", + "\n", + " # Associate PhoneNumber with ConversationProfile\n", + "\n", + " print(\"\\nAssociating Phone Number with Conversation Profile:\\n\")\n", + " associate_phone_number_with_conv_profile = f\"\"\"\n", + " curl -X PATCH \\\n", + " -H \"Authorization: Bearer {JWT}\" \\\n", + " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + " -H \"Content-Type: application/json; charset=utf-8\" \\\n", + " -d '{{\n", + " \"conversationProfile\": \"{conversation_profile_obj_name}\"\n", + " }}' \\\n", + " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{phone_number_name}?update_mask=conversationProfile\n", + " \"\"\"\n", + "\n", + " response = json.loads(os.popen(associate_phone_number_with_conv_profile).read())\n", + " print(response)\n", + "\n", + "print(\"\\nDone!\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZVWKweSromS1" + }, + "source": [ + "# SIP Trunk Creation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "bDz5RHChPzKK" + }, + "outputs": [], + "source": [ + "# @title CreateSipTrunk\n", + "\n", + "HOSTNAMES = [\"host.na.me1\", \"host.na.me2\"] # @param\n", + "DISPLAY_NAME = \"sip_trunk_name\" # @param {type:\"string\"}\n", + "\n", + "\n", + "hostname_expression = \"\"\n", + "for host in HOSTNAMES:\n", + " hostname_expression += f'\"expected_hostname\": \"{host}\",'\n", + "\n", + "curl = f\"\"\"\n", + "curl -X POST \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "-d '{{\n", + " {hostname_expression}\n", + " \"display_name\": \"{DISPLAY_NAME}\"\n", + " }}' \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/sipTrunks\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TYmxJhBo2RDm" + }, + "source": [ + "# Utility functions (List/Get/Delete methods for resources created)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "1xPq_CC72bPq" + }, + "outputs": [], + "source": [ + "# @title View ConversationProfile and PhoneNumber details\n", + "\n", + "conversation_profiles_dict = {}\n", + "orphan_phone_numbers = []\n", + "\n", + "# Get all the ConversationProfiles and see which ones have sipConfig configured\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, str):\n", + " response = json.loads(request)\n", + "\n", + " for data in response[\"conversationProfiles\"]:\n", + " conversation_profile_name = data[\"name\"]\n", + " conversation_profiles_dict[conversation_profile_name] = {}\n", + " # print(data)\n", + " if \"sipConfig\" in data:\n", + " conversation_profiles_dict[conversation_profile_name][\"sipConfig\"] = data[\"sipConfig\"]\n", + " if \"automatedAgentConfig\" in data:\n", + " conversation_profiles_dict[conversation_profile_name][\"automatedAgentConfig\"] = data[\"automatedAgentConfig\"]\n", + "\n", + "# Get all phone numbers and see which ones are associated with a ConversationProfile\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/phoneNumbers\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, str):\n", + " response = json.loads(request)\n", + "\n", + " if \"phoneNumbers\" in response:\n", + " for data in response[\"phoneNumbers\"]:\n", + " phone_number = data[\"phoneNumber\"]\n", + " if \"conversationProfile\" in data:\n", + " conversation_profile_name = data[\"conversationProfile\"]\n", + " conversation_profiles_dict[conversation_profile_name][\"phone_number\"] = phone_number\n", + " else:\n", + " orphan_phone_numbers.append(phone_number)\n", + "\n", + " if orphan_phone_numbers:\n", + " print(f\"There is/are {len(orphan_phone_numbers)} phone numbers not associated with a ConversationProfile:\\n {orphan_phone_numbers}\\n\\n\")\n", + "\n", + " for conversation_profile_name, details in conversation_profiles_dict.items():\n", + " print(f\"Conversation Profile: {conversation_profile_name}\")\n", + " if details:\n", + " if \"sipConfig\" in details and details[\"sipConfig\"]:\n", + " print(f\"SipConfig is set: {details['sipConfig']}\")\n", + " if \"automatedAgentConfig\" in details:\n", + " print(f\"Virtual agent is configured: {details['automatedAgentConfig']}\")\n", + " if \"phone_number\" in details:\n", + " print(f\"Phone number is associated: {details['phone_number']}\")\n", + " print(\"\\n\")\n", + " else:\n", + " print(\"No phone numbers present\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "eLSdPEMWcGhf" + }, + "outputs": [], + "source": [ + "# @title GetConversation\n", + "\n", + "conversation_name = \"projects//locations//conversations/\" # @param {type:\"string\"}\n", + "\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{conversation_name}\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "W-wa4CZGwVJL" + }, + "outputs": [], + "source": [ + "# @title ListSecuritySettings\n", + "\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v3/projects/{PROJECT_ID}/locations/{REGION}/securitySettings\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "s7MfoE_IRyce" + }, + "outputs": [], + "source": [ + "# @title ListConversationProfiles\n", + "\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/conversationProfiles\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "jcL-Vtz5evzX" + }, + "outputs": [], + "source": [ + "# @title ListPhoneNumbers\n", + "\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/phoneNumbers\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "executionInfo": { + "elapsed": 10, + "status": "ok", + "timestamp": 1728507630448, + "user": { + "displayName": "", + "userId": "" + }, + "user_tz": 420 }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "-a-pAFZEQ6Jl" - }, - "outputs": [], - "source": [ - "# @title DeleteSipTrunk\n", - "\n", - "RESOURCE_NAME = \"projects//locations//sipTrunks/\" # @param {type:\"string\"}\n", - "# eg. value projects/project_name/locations/global/sipTrunks/JxN1ndLCR9OJvgrDlc32_Q\n", - "\n", - "\n", - "curl = f\"\"\"\n", - "curl -X DELETE \\\n", - "-H \"Authorization: Bearer {JWT}\" \\\n", - "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", - "-H \"Content-Type: application/json; charset=utf-8\" \\\n", - "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{RESOURCE_NAME}\n", - "\"\"\"\n", - "\n", - "request = os.popen(curl).read()\n", - "if isinstance(request, dict):\n", - " response = json.loads(request)\n", - " print(response)\n", - "else:\n", - " print(request)" - ] - } - ], - "metadata": { + "id": "y6UmqCDL6UB_" + }, + "outputs": [], + "source": [ + "# @title Delete resource objects\n", + "\n", + "resource_name = \"projects//locations///\" # @param {type:\"string\"}\n", + "\n", + "security_settings_name = \"\"\n", + "conversation_profile_name = \"\"\n", + "phone_number_name = \"\"\n", + "\n", + "\n", + "security_settings_pattern = \"^projects/([^/]+)/locations/([^/]+)/securitySettings/([^/]+)\"\n", + "# Security settings uses the v3alpha1 api\n", + "if re.search(security_settings_pattern, resource_name):\n", + " print(\"Deleting Security Settings object: \" + resource_name)\n", + " curl = f\"\"\"\n", + " curl -X DELETE \\\n", + " -H \"Authorization: Bearer {JWT}\" \\\n", + " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + " -H \"Content-Type: application/json; charset=utf-8\" \\\n", + " https://{LOCATION_ID}dialogflow.googleapis.com/v3alpha1/{resource_name}\n", + " \"\"\"\n", + " response = json.loads(os.popen(curl).read())\n", + " print(response)\n", + "\n", + "conversation_profile_pattern = \"^projects/([^/]+)/locations/([^/]+)/conversationProfiles/([^/]+)\"\n", + "phone_number_pattern = \"^projects/([^/]+)/locations/([^/]+)/phoneNumbers/([^/]+)\"\n", + "\n", + "# ConversationProfile and PhoneNumbers use the v2beta1 api\n", + "if (re.search(conversation_profile_pattern, resource_name) or\n", + " re.search(phone_number_pattern, resource_name)):\n", + " print(\"Deleting object: \" + resource_name)\n", + " curl = f\"\"\"\n", + " curl -X DELETE \\\n", + " -H \"Authorization: Bearer {JWT}\" \\\n", + " -H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + " -H \"Content-Type: application/json; charset=utf-8\" \\\n", + " https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{resource_name}\n", + " \"\"\"\n", + " response = json.loads(os.popen(curl).read())\n", + " print(response)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "wreAsBY3L3Lk" + }, + "outputs": [], + "source": [ + "# @title ListSipTrunks\n", + "\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/projects/{PROJECT_ID}/locations/{REGION}/sipTrunks\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "cellView": "form", "colab": { - "collapsed_sections": [ - "o5wTWF_HowQf", - "ZVWKweSromS1", - "TYmxJhBo2RDm" - ], - "name": "SIP_SIPREC_integration_Dialogflow_CURL_commands_with_SIP_TRUNK_management.ipynb", - "provenance": [] + "base_uri": "https://localhost:8080/" }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" + "executionInfo": { + "elapsed": 6, + "status": "ok", + "timestamp": 1728507630448, + "user": { + "displayName": "", + "userId": "" + }, + "user_tz": 420 }, - "language_info": { - "name": "python" + "id": "L9ixrCWimlqB", + "outputId": "7a0ae3ea-61e7-4068-fe84-b4f8724c1cff" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] } + ], + "source": [ + "# @title GetSipTrunk\n", + "\n", + "RESOURCE_NAME = \"projects//locations//sipTrunks/\" # @param {type:\"string\"}\n", + "# eg. value projects/project_name/locations/global/sipTrunks/JxN1ndLCR9OJvgrDlc32_Q\n", + "\n", + "curl = f\"\"\"\n", + "curl -X GET \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{RESOURCE_NAME}\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "-a-pAFZEQ6Jl" + }, + "outputs": [], + "source": [ + "# @title DeleteSipTrunk\n", + "\n", + "RESOURCE_NAME = \"projects//locations//sipTrunks/\" # @param {type:\"string\"}\n", + "# eg. value projects/project_name/locations/global/sipTrunks/JxN1ndLCR9OJvgrDlc32_Q\n", + "\n", + "\n", + "curl = f\"\"\"\n", + "curl -X DELETE \\\n", + "-H \"Authorization: Bearer {JWT}\" \\\n", + "-H \"X-Goog-User-Project: {PROJECT_ID}\" \\\n", + "-H \"Content-Type: application/json; charset=utf-8\" \\\n", + "https://{LOCATION_ID}dialogflow.googleapis.com/v2beta1/{RESOURCE_NAME}\n", + "\"\"\"\n", + "\n", + "request = os.popen(curl).read()\n", + "if isinstance(request, dict):\n", + " response = json.loads(request)\n", + " print(response)\n", + "else:\n", + " print(request)" + ] + } + ], + "metadata": { + "colab": { + "collapsed_sections": [ + "o5wTWF_HowQf", + "ZVWKweSromS1", + "TYmxJhBo2RDm" + ], + "name": "SIP_SIPREC_integration_Dialogflow_CURL_commands_with_SIP_TRUNK_management.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" }, - "nbformat": 4, - "nbformat_minor": 0 + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 }