Skip to content

Commit

Permalink
Fix-allowlisting-check (#264)
Browse files Browse the repository at this point in the history
* Refactor based on customer experience

* Update project id
  • Loading branch information
vdlima authored Sep 17, 2024
1 parent 9062b3a commit e4ef349
Showing 1 changed file with 89 additions and 74 deletions.
163 changes: 89 additions & 74 deletions tools/SIP_SIPREC_integration_Dialogflow_CURL_commands.ipynb
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "BDe-MhXg2U7C"
},
"outputs": [],
"source": [
"from google.colab import auth as google_auth\n",
"\n",
Expand All @@ -24,22 +15,17 @@
"import re\n",
"import sys\n",
"\n",
"google_auth.authenticate_user()\n",
"\n",
"# @title Input parameters\n",
"\n",
"PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n",
"REGION = \"global\" # @param {type:\"string\"}\n",
"JWT = \"Leave as-is to use SSO or enter generated JWT token here\" # @param {type:\"string\"}\n",
"\n",
"\n",
"# Ensure that the project has Dialogflow APIs enabled\n",
"!gcloud config set project {PROJECT_ID}\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",
" google_auth.authenticate_user()\n",
" JWT = !gcloud auth print-access-token\n",
" JWT = JWT[0]\n",
"\n",
Expand All @@ -48,15 +34,32 @@
" LOCATION_ID = \"\"\n",
"else:\n",
" LOCATION_ID = REGION + \"-\""
],
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "BDe-MhXg2U7C"
"id": "9ohBmJNaiZgr"
},
"execution_count": null,
"outputs": []
"outputs": [],
"source": [
"# @title ** DO NOT USE IF USING A JWT** Enable the Dialogflow API in your project\n",
"\n",
"google_auth.authenticate_user()\n",
"\n",
"# Ensure that the project has Dialogflow APIs enabled\n",
"!gcloud config set project {PROJECT_ID}\n",
"!gcloud services enable dialogflow.googleapis.com"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "UmNL7NISdGgp"
},
"outputs": [],
"source": [
"# @title Create a Dummy ES agent and set the tier to Enterprise in order make quota requests\n",
"\n",
Expand All @@ -74,15 +77,15 @@
"\"\"\"\n",
"\n",
"json.loads(os.popen(create_dummy_agent).read())"
],
"metadata": {
"id": "UmNL7NISdGgp"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "s2lzeQoq3i3X"
},
"outputs": [],
"source": [
"# @title Script to create a ConversationProfile with GTP integration and export to Insights enabled\n",
"\n",
Expand All @@ -98,6 +101,9 @@
" print(\"No Dialogflow CX agent name provided.\")\n",
" virtual_agent = False\n",
"\n",
"project_allowlisted = True\n",
"\n",
"\n",
"# Create PhoneNumberOrder\n",
"\n",
"print(\"\\nCreating Phone Number Order Object:\\n\")\n",
Expand All @@ -124,9 +130,9 @@
" 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_not_allowlisted = True\n",
" project_allowlisted = False\n",
"\n",
"if not project_not_allowlisted:\n",
"if project_allowlisted:\n",
"\n",
" # Create Security Settings object\n",
"\n",
Expand Down Expand Up @@ -213,15 +219,15 @@
" print(response)\n",
"\n",
"print(\"\\nDone!\")"
],
"metadata": {
"id": "s2lzeQoq3i3X"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "1xPq_CC72bPq"
},
"outputs": [],
"source": [
"# @title View ConversationProfile and PhoneNumber details\n",
"\n",
Expand Down Expand Up @@ -280,24 +286,24 @@
" if \"phone_number\" in details:\n",
" print(f\"Phone number is associated: {details['phone_number']}\")\n",
" print(\"\\n\")"
],
"metadata": {
"id": "1xPq_CC72bPq"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"source": [
"# Utility functions"
],
"metadata": {
"id": "TYmxJhBo2RDm"
}
},
"source": [
"# Utility functions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "W-wa4CZGwVJL"
},
"outputs": [],
"source": [
"# @title ListSecuritySettings\n",
"\n",
Expand All @@ -311,15 +317,15 @@
"\n",
"response = json.loads(os.popen(curl).read())\n",
"response"
],
"metadata": {
"id": "W-wa4CZGwVJL"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "s7MfoE_IRyce"
},
"outputs": [],
"source": [
" # @title ListConversationProfiles\n",
"\n",
Expand All @@ -333,15 +339,15 @@
"\n",
"response = json.loads(os.popen(curl).read())\n",
"response"
],
"metadata": {
"id": "s7MfoE_IRyce"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jcL-Vtz5evzX"
},
"outputs": [],
"source": [
"# @title ListPhoneNumbers\n",
"\n",
Expand All @@ -355,15 +361,15 @@
"\n",
"response = json.loads(os.popen(curl).read())\n",
"response"
],
"metadata": {
"id": "jcL-Vtz5evzX"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "y6UmqCDL6UB_"
},
"outputs": [],
"source": [
"# @title Delete resource objects\n",
"\n",
Expand Down Expand Up @@ -404,12 +410,21 @@
" \"\"\"\n",
" response = json.loads(os.popen(curl).read())\n",
" print(response)"
],
"metadata": {
"id": "y6UmqCDL6UB_"
},
"execution_count": null,
"outputs": []
]
}
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit e4ef349

Please sign in to comment.