#If you haven't already, make sure you install the `dfcx-scrapi` library

!pip install dfcx-scrapi

"""
Explanation: Introduction
In this notebook, we will demonstrate how Google Sheets can be used as a simple medium for managing, updating, and evaluating Intents and Training Phrases in Dialogflow CX.
Specifically, we will show how to update Existing Intents and Training Phrases in Dialogflow CX using Google Sheets as a Source
Prerequisites

Ensure you have a GCP Service Account key with the Dialogflow API Admin privileges assigned to it
End of explanation
"""


from dfcx_scrapi.core.intents import Intents
from dfcx_scrapi.tools.dataframe_functions import DataframeFunctions

"""
Explanation: Imports
End of explanation
"""


creds_path = '<YOUR_CREDS_PATH_HERE>'
agent_id = '<YOUR_AGENT_ID_HERE>'
google_sheet_name = 'My Google Sheet Name'
google_sheet_tab_read = 'Read From My Tab Name'

"""
Explanation: User Inputs
In the next section, we will collect runtime variables needed to execute this notebook. 
This should be the only cell of the notebook you need to edit in order for this notebook to run.
For this notebook, we'll need the following inputs:

creds_path: Your local path to your GCP Service Account Credentials
agent_id: Your Dialogflow CX Agent ID in String format
google_sheet_name: The name of your Google Sheet
google_sheet_tab_read:  The name of the tab in your Google Sheet to read the data from
End of explanation
"""


dffx = DataframeFunctions(creds_path)

df = dffx.sheets_to_dataframe(google_sheet_name, google_sheet_tab_read)
dffx.bulk_update_intents_from_dataframe(agent_id, df, update_flag=True, rate_limiter=1)

"""
Explanation: Sheets to CX
Here, we'll demonstrate how to update an Existing Intent in your Dialogflow CX Agent based on data from a Google Sheet.
Prerequisites

In order for the DataframeFunctions class to interact with Google Sheets, you must share your Google Sheet with your Service Account email address.
For this specific function, you must have exactly 2 columns with the following names:
display_name
text
End of explanation
"""


