-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support for data stores #192
base: master
Are you sure you want to change the base?
Changes from all commits
95a5b04
396a946
0d5bff3
82dbb12
77e7581
cea171d
56926e8
1d8f1ea
c1eabc0
2c8adf2
01fa099
191595e
e217089
d1c2447
3980f89
5223be1
8b0f11d
c65d454
7829c3f
ed4d97e
7b353b8
7574934
c16b85d
77d875c
34fa2e6
74805ec
d33ac05
4fd0b0c
7473634
1dff995
91518d6
67d03e1
2a86850
6605a56
f4beab0
878d4f0
e175305
bd4b795
69a4726
90f102f
122de74
43886c6
8234874
8df78cd
be73cce
543409f
fe0ce9b
c3b3bfb
13f3a0e
d1e0328
38dcaba
8f9888b
6c71b39
1ef0a5d
a2c56a2
4ac91e5
2ebb288
ea179a3
736b40c
fc9f7e5
20a513f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
run: | ||
go: 1.20 | ||
go: 1.23 | ||
linters: | ||
enable: | ||
- thelper | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json | ||
reviews: | ||
path_filters: | ||
- "!**/*.mod" | ||
- "!**/*.sum" | ||
- "!docs/docs/cmd/*.md" | ||
auto_review: | ||
enabled: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package datastore | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/xavidop/dialogflow-cx-cli/cmd/cmdutils" | ||
cmdducment "github.com/xavidop/dialogflow-cx-cli/cmd/datastore/document" | ||
) | ||
|
||
// datastoreCmd represents the datastore root command | ||
var datastoreCmd = &cobra.Command{ | ||
Use: "datastore", | ||
Aliases: []string{"ds"}, | ||
Short: "Actions on datastore commands", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cmd.Help(); err != nil { | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
}, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
cmdutils.PreRun(cmd.Name()) | ||
}, | ||
PersistentPostRun: func(cmd *cobra.Command, args []string) { | ||
}, | ||
} | ||
|
||
func Register(rootCmd *cobra.Command) { | ||
rootCmd.AddCommand(datastoreCmd) | ||
} | ||
|
||
func init() { | ||
cmdducment.Register(datastoreCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package datastore | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/xavidop/dialogflow-cx-cli/cmd/cmdutils" | ||
"github.com/xavidop/dialogflow-cx-cli/internal/global" | ||
"github.com/xavidop/dialogflow-cx-cli/pkg/datastore" | ||
) | ||
|
||
// deleteCmd represents the search datastore set command | ||
var deleteCmd = &cobra.Command{ | ||
Use: "delete [name]", | ||
Aliases: []string{"deletes", "d", "del"}, | ||
Short: "delete a datastore", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Get the information | ||
locationID, _ := cmd.Flags().GetString("location-id") | ||
projectID, _ := cmd.Flags().GetString("project-id") | ||
name := args[0] | ||
|
||
if err := datastore.Delete(name, locationID, projectID); err != nil { | ||
global.Log.Errorf("%s", err.Error()) | ||
os.Exit(1) | ||
} | ||
}, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
cmdutils.PreRun(cmd.Name()) | ||
}, | ||
PersistentPostRun: func(cmd *cobra.Command, args []string) { | ||
}, | ||
} | ||
|
||
func init() { | ||
datastoreCmd.AddCommand(deleteCmd) | ||
|
||
deleteCmd.Flags().StringP("project-id", "p", "", "Data Store Project ID (required)") | ||
if err := deleteCmd.MarkFlagRequired("project-id"); err != nil { | ||
global.Log.Errorf("%s", err.Error()) | ||
os.Exit(1) | ||
} | ||
deleteCmd.Flags().StringP("location-id", "l", "", "Data Store Location ID of the Project (required)") | ||
if err := deleteCmd.MarkFlagRequired("location-id"); err != nil { | ||
global.Log.Errorf("%s", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package document | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/xavidop/dialogflow-cx-cli/cmd/cmdutils" | ||
) | ||
|
||
// documentCmd represents the datastore root command | ||
var documentCmd = &cobra.Command{ | ||
Use: "document", | ||
Aliases: []string{"dc"}, | ||
Short: "Actions on datastore document commands", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cmd.Help(); err != nil { | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
}, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
cmdutils.PreRun(cmd.Name()) | ||
}, | ||
PersistentPostRun: func(cmd *cobra.Command, args []string) { | ||
}, | ||
} | ||
|
||
func Register(rootCmd *cobra.Command) { | ||
rootCmd.AddCommand(documentCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package datastore | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/xavidop/dialogflow-cx-cli/cmd/cmdutils" | ||
"github.com/xavidop/dialogflow-cx-cli/internal/global" | ||
"github.com/xavidop/dialogflow-cx-cli/pkg/datastore" | ||
) | ||
|
||
// searchCmd represents the search datastore set command | ||
var searchCmd = &cobra.Command{ | ||
Use: "search [name]", | ||
Aliases: []string{"searches", "s"}, | ||
Short: "search in a datastore", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Get the information | ||
locationID, _ := cmd.Flags().GetString("location-id") | ||
projectID, _ := cmd.Flags().GetString("project-id") | ||
query, _ := cmd.Flags().GetString("query") | ||
name := args[0] | ||
|
||
if err := datastore.Search(name, locationID, projectID, query); err != nil { | ||
global.Log.Errorf(err.Error()) | ||
os.Exit(1) | ||
} | ||
}, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
cmdutils.PreRun(cmd.Name()) | ||
}, | ||
PersistentPostRun: func(cmd *cobra.Command, args []string) { | ||
}, | ||
} | ||
|
||
func init() { | ||
datastoreCmd.AddCommand(searchCmd) | ||
|
||
searchCmd.Flags().StringP("query", "r", "", "Query to search (required)") | ||
if err := searchCmd.MarkFlagRequired("query"); err != nil { | ||
global.Log.Errorf(err.Error()) | ||
os.Exit(1) | ||
} | ||
searchCmd.Flags().StringP("project-id", "p", "", "Data Store Project ID (required)") | ||
if err := searchCmd.MarkFlagRequired("project-id"); err != nil { | ||
global.Log.Errorf(err.Error()) | ||
os.Exit(1) | ||
} | ||
searchCmd.Flags().StringP("location-id", "l", "", "Data Store Location ID of the Project (required)") | ||
if err := searchCmd.MarkFlagRequired("location-id"); err != nil { | ||
global.Log.Errorf(err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,6 +31,7 @@ cxcli [flags] | |||||
|
||||||
* [cxcli agent](/cmd/cxcli_agent/) - Actions on agent commands | ||||||
* [cxcli completion](/cmd/cxcli_completion/) - Generate the autocompletion script for the specified shell | ||||||
* [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace hard tabs with spaces. - * [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands
+ * [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands Committable suggestion
Suggested change
|
||||||
* [cxcli dialog](/cmd/cxcli_dialog/) - Test your CX Agent interactively directly from your terminal | ||||||
* [cxcli entity-type](/cmd/cxcli_entity-type/) - Actions on entity type commands | ||||||
* [cxcli environment](/cmd/cxcli_environment/) - Actions on environment | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# cxcli datastore | ||
|
||
Actions on datastore commands | ||
|
||
``` | ||
cxcli datastore [flags] | ||
``` | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify the language for the code block. - ```
+ ```sh |
||
|
||
## Options | ||
|
||
``` | ||
-h, --help help for datastore | ||
``` | ||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify the language for the code block. - ```
+ ```sh |
||
|
||
## Options inherited from parent commands | ||
|
||
``` | ||
-c, --credentials string Google Cloud credentials JSON file path (optional) | ||
-o, --output-format string Output Format. Options: text, json. Default: text (optional) (default "text") | ||
-u, --skip-update-check Skip the check for updates check run before every command (optional) | ||
-v, --verbose verbose error output (with stack trace) (optional) | ||
``` | ||
Comment on lines
+17
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify the language for the code block. - ```
+ ```sh |
||
|
||
## See also | ||
|
||
* [cxcli](/cmd/cxcli/) - Dialogflow CX CLI | ||
* [cxcli datastore search](/cmd/cxcli_datastore_search/) - search in a datastore | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||
# cxcli datastore search | ||||||
|
||||||
search in a datastore | ||||||
|
||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify language for code block. To improve readability, specify the language for the code block. - ```
+ ```sh |
||||||
cxcli datastore search [name] [flags] | ||||||
``` | ||||||
|
||||||
## Options | ||||||
|
||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify language for code block. To improve readability, specify the language for the code block. - ```
+ ```sh |
||||||
-h, --help help for search | ||||||
-l, --location-id string Data Store Location ID of the Project (required) | ||||||
-p, --project-id string Data Store Project ID (required) | ||||||
-r, --query string Query to search (required) | ||||||
``` | ||||||
|
||||||
## Options inherited from parent commands | ||||||
|
||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify language for code block. To improve readability, specify the language for the code block. - ```
+ ```sh |
||||||
-c, --credentials string Google Cloud credentials JSON file path (optional) | ||||||
-o, --output-format string Output Format. Options: text, json. Default: text (optional) (default "text") | ||||||
-u, --skip-update-check Skip the check for updates check run before every command (optional) | ||||||
-v, --verbose verbose error output (with stack trace) (optional) | ||||||
``` | ||||||
|
||||||
## See also | ||||||
|
||||||
* [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove hard tabs. Replace hard tabs with spaces for consistent formatting. - * [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands
+ * [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands Committable suggestion
Suggested change
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Webhooks | ||
|
||
## What is this? | ||
|
||
Webhooks serve as platforms for hosting your business logic or invoking other services. Within a session, webhooks enable you to utilize the data extracted through Dialogflow's natural language processing to generate dynamic responses, verify gathered data, or initiate actions on the backend. | ||
|
||
There are two types of webhooks: standard webhooks and flexible webhooks. In the case of a standard webhook, the request and response fields are determined by Dialogflow. On the other hand, a flexible webhook allows you to specify the request and response fields according to your requirements. | ||
|
||
With `cxcli`, you can easily interact with the webhooks of your Dialogflow CX agents. | ||
|
||
All of the commands that you have available in `cxcli` to interact with your webhooks are located within the `cxcli webhook` subcommand. | ||
|
||
You can create, update or delete standard and flexible webhooks with `cxcli` for a specific environment by setting the `--environment` parameter. If you do not specify an environment, the `cxcli` will create, update or delete this webhook for all environments. | ||
|
||
## Create | ||
|
||
The `cxcli` has a command that allows you to create a standard or flexible webhook. You can find a more detailed information [here](/webhooks/create). | ||
|
||
## Update | ||
|
||
The `cxcli` has a command that allows you to update a standard or flexible webhook. You can find a more detailed information [here](/webhooks/update). | ||
|
||
## Delete | ||
|
||
The `cxcli` has a command that allows you to delete your standard or flexible webhook. You can find a more detailed explanation [here](/webhooks/delete). | ||
|
||
## Useful Links | ||
|
||
If you want to see the full usage of the `cxcli webhook` command, please refer to this [page](/cmd/cxcli_webhook). | ||
|
||
If you want to learn more about Dialogflow CX webhooks, refer to the [official documentation](https://cloud.google.com/dialogflow/cx/docs/concept/webhook). |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,51 @@ | ||||||||||
# Create | ||||||||||
|
||||||||||
|
||||||||||
## Usage | ||||||||||
|
||||||||||
You can find the create functionality within the `cxcli webhook create` subcommand. You can read the documentation about this command [here](/cmd/cxcli_webhook_create). | ||||||||||
|
||||||||||
### Flexible Webhook | ||||||||||
|
||||||||||
If you want to create a flexible webhook, you have to set the `--flexible` parameter. When you set these parameters, you have to provide a `--request-body` and a `--parameters-mapping` parameter: | ||||||||||
|
||||||||||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing spaces. - If you want to create a flexible webhook, you have to set the `--flexible` parameter. When you set these parameters, you have to provide a `--request-body` and a `--parameters-mapping` parameter:
+ If you want to create a flexible webhook, you have to set the `--flexible` parameter. When you set these parameters, you have to provide a `--request-body` and a `--parameters-mapping` parameter: Committable suggestion
Suggested change
|
||||||||||
1. The `--request-body` parameter is a JSON string that will be sent to the webhook. | ||||||||||
2. The `--parameters-mapping` parameter is a comma-separated list of key-value pairs. The key is the name of the parameter that will be sent to the webhook, and the value is a JSON path that will be used to extract the value from the `--request-body` parameter. This parameter has the following format: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surround lists with blank lines. - 2. The `--parameters-mapping` parameter is a comma-separated list of key-value pairs. The key is the name of the parameter that will be sent to the webhook, and the value is a JSON path that will be used to extract the value from the `--request-body` parameter. This parameter has the following format:
+
+ 2. The `--parameters-mapping` parameter is a comma-separated list of key-value pairs. The key is the name of the parameter that will be sent to the webhook, and the value is a JSON path that will be used to extract the value from the `--request-body` parameter. This parameter has the following format: Committable suggestion
Suggested change
|
||||||||||
``` | ||||||||||
parameter@json-path,paramter2@json-path2 | ||||||||||
``` | ||||||||||
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surround fenced code blocks with blank lines and specify the language. - ```
+
+ ```sh
parameter@json-path,paramter2@json-path2
- ```
+ ``` |
||||||||||
An example of a parameter mapping: `my-param@$.fully.qualified.path.to.field` | ||||||||||
|
||||||||||
## Example | ||||||||||
|
||||||||||
### Standard Webhook | ||||||||||
|
||||||||||
Here is a simple example of using the `cxcli webhook create` command: | ||||||||||
|
||||||||||
```sh | ||||||||||
cxcli webhook create my-webhook --url "https://my-webhook.com" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1 | ||||||||||
``` | ||||||||||
|
||||||||||
The above command will give you output similar to the following: | ||||||||||
|
||||||||||
```sh | ||||||||||
$ cxcli webhook create my-webhook --url "https://my-webhook.com" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1 | ||||||||||
INFO Webhook created with id: projects/test-cx-346408/locations/us-central1/agents/40278ea0-c0fc-4d9a-a4d4-caa68d86295f/webhooks/55f56aeb-be30-40a2-8bd6-cbbd6b9cc041 | ||||||||||
``` | ||||||||||
|
||||||||||
### Flexible Webhook | ||||||||||
|
||||||||||
```sh | ||||||||||
cxcli webhook create my-webhook --url "https://my-webhook.com" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1 --flexible true --request-body "{\"hello\": true}" --parameters-mapping "my-param@$.fully.qualified.path.to.field, my-param2@$.fully.qualified.path.to.field2" | ||||||||||
``` | ||||||||||
|
||||||||||
The above command will give you output similar to the following: | ||||||||||
|
||||||||||
```sh | ||||||||||
$ cxcli webhook create my-webhook --url "https://my-webhook.com" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1 --flexible true --request-body "{\"hello\": true}" --parameters-mapping "my-param@$.fully.qualified.path.to.field, my-param2@$.fully.qualified.path.to.field2" | ||||||||||
INFO Webhook created with id: projects/test-cx-346408/locations/us-central1/agents/40278ea0-c0fc-4d9a-a4d4-caa68d86295f/webhooks/13df6f13-6848-4fab-8cda-752b4f9819fa | ||||||||||
``` | ||||||||||
|
||||||||||
## Useful Links | ||||||||||
|
||||||||||
If you want to learn more about Dialogflow CX webhook creation, refer to the [official documentation](https://cloud.google.com/dialogflow/cx/docs/concept/webhook). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error context.
To provide more context in the error message, consider wrapping the error with additional information.
Committable suggestion