Package: dfcx-scrapi
Python Dialogflow CX Scripting API (SCRAPI)A high level scripting API for bot builders, developers, and maintainers.Table of ContentsIntroductionWhat Can I Do with SCRAPI?Built WithGetting StartedEnvironment SetupAuthenticationUsageLibrary CompositionCoreToolsContributingLicenseContactAcknowledgementsIntroductionThe Python Dialogflow CX Scripting API (DFCX SCRAPI) is a high level API that extends the official GooglePython Client for Dialogflow CX. SCRAPI makes using DFCX easier, more friendly, and more pythonic for bot builders, developers, and maintainers.SCRAPI --> Python Dialogflow CX
as
Keras --> TensorflowWhat Can I Do With DFCX SCRAPI?With DFCX SCRAPI you can perform many bot building and maintenance actions at scale including, but not limited to:Create, Update, Delete, Get, and List for all CX resources types (i.e. Intents, Entity Types, Pages, Flows, etc.)Convert commonly accessed CX Resources to Pandas DataframesHave fully automated conversations with a CX agent (powerful for regression testing!)Extract Validation informationExtract Change History informationSearch across all Flows/Pages/Routes to find a specific parameter or utterance using Search Util functionsQuickly move CX resources between agents using Copy Util functions!Build the fundamental protobuf objects that CX uses for each resource type using Builder methods...and much, much more!Built WithPython 3.8+AuthenticationAuthentication can vary depending on how and where you are interacting with SCRAPI.Google ColabIf you're using SCRAPI with aGoogle Colabnotebook, you can add the following to the top of your notebook for easy authentication:project_id='<YOUR_GCP_PROJECT_ID>'# this will launch an interactive prompt that allows you to auth with GCP in a browser!gcloudauthapplication-defaultlogin--no-launch-browser# this will set your active project to the `project_id` above!gcloudauthapplication-defaultset-quota-project$project_idAfter running the above, Colab will pick up your credentials from the environment and pass them to SCRAPI directly. No need to use Service Account keys!
You can then use SCRAPI simply like this:fromdfcx_scrapi.core.intentsimportIntentsagent_id='<YOUR_AGENT_ID>'i=Intents()# <-- Creds will be automatically picked up from the environmentintents_map=i.get_intents_map(agent_id)Cloud Functions / Cloud RunIf you're using SCRAPI withCloud FunctionsorCloud Run, SCRAPI can pick up on the default environment creds used by these services without any additional configuration!Adddfcx-scrapito yourrequirements.txtfileEnsure the Cloud Function / Cloud Run service account has the appropriate Dialogflow IAM RoleOnce you are setup with the above, your function code can be used easily like this:fromdfcx_scrapi.core.intentsimportIntentsagent_id='<YOUR_AGENT_ID>'i=Intents()# <-- Creds will be automatically picked up from the environmentintents_map=i.get_intents_map(agent_id)Local Python EnvironmentSimilar to Cloud Functions / Cloud Run, SCRAPI can pick up on your local authentication credsif you are using the gcloud CLI.Installgcloud CLI.Rungcloud init.Rungcloud auth loginRungcloud auth listto ensure your principal account is active.This will authenticate your principal GCP account with the gcloud CLI, and SCRAPI can pick up the creds from here.Exceptions and Misc.There are some classes in SCRAPI which still rely on Service Account Keys, notably theDataframeFunctionsclass due to how it authenticates with Google Sheets.In order to use these functions, you will need a Service Account that has appropriate access to your GCP project.For more information and to view the official documentation for service accounts go toCreating and Managing GCP Service Accounts.Once you've obtained a Service Account Key with appropriate permissions, you can use it as follows:fromdfcx_scrapi.core.intentsimportIntentsfromdfcx_scrapi.tools.dataframe_functionsimportDataframeFunctionsagent_id='<YOUR_AGENT_ID>'creds_path='<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON_FILE>'i=Intents(creds_path=creds_path)dffx=DataframeFunctions(creds_path=creds_path)df=i.bulk_intent_to_df(agent_id)dffx.dataframe_to_sheets('GOOGLE_SHEET_NAME','TAB_NAME',df)Getting StartedEnvironment SetupSet up Google Cloud Platform credentials and install dependencies.gcloudauthlogin
gcloudauthapplication-defaultlogin
gcloudconfigsetproject<projectname>python3-mvenvvenvsource./venv/bin/activate
pipinstall-rrequirements.txtUsageTo run a simple bit of code you can do the following:Import a Class fromdfcx_scrapi.coreAssign your Service Account to a local variablefromdfcx_scrapi.core.intentsimportIntentscreds_path='<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON_FILE>'agent_path='<FULL_DFCX_AGENT_ID_PATH>'# DFCX Agent ID paths are in this format:# 'projects/<project_id>/locations/<location_id>/agents/<agent_id>'# Instantiate your class object and pass in your credentialsi=Intents(creds_path,agent_id=agent_path)# Retrieve all Intents and Training Phrases from an Agent and push to a Pandas DataFramedf=i.bulk_intent_to_df()Library CompositionHere is a brief overview of the SCRAPI library's structure and the motivation behind that structure.CoreTheCorefolder is synonymous with the core Resource types in the DFCX Agents (agents, intents, flows, etc.)This folder contains the high level building blocks of SCRAPIThese classes and methods can be used to build higher level methods or custom tools and applicationsToolsTheToolsfolder contains various customized toolkits that allow you to do more complex bot management tasks, such asManipulate Agent Resource types into various DataFrame structuresCopy Agent Resources between Agents and GCP Projects on a resource by resource levelMove data to and from DFCX and other GCP Services like BigQuery, Sheets, etc.Create customized search queries inside of your agent resourcesBuildersTheBuildersfolder contains simple methods for constructing the underlying protos in Dialogflow CXProto objects are the fundamental building blocks of Dialogflow CXBuilder classes allow the user to construct Dialogflow CX resourceofflinewithout any API callsOnce the resource components are constructed, they can then be pushed to a live Dialogflow CX agent via APIContributingWe welcome any contributions or feature requests you would like to submit!Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull RequestLicenseDistributed under the Apache 2.0 License. SeeLICENSEfor more information.ContactPatrick Marlow -pmarlow@google.com-@kmaphoenixMilad Tabrizi -miladt@google.com-@MRyderOCProject Link:https://github.com/GoogleCloudPlatform/dfcx-scrapiAcknowledgementsDialogflow CX Python Client LibraryHugging Face - Pegasus Paraphrase