Skip to content
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

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
95a5b04
faet: support to data stores
xavidop Dec 29, 2023
396a946
fix: update year
xavidop Dec 29, 2023
0d5bff3
feat: boilerplate docs and cmd features
xavidop Dec 30, 2023
82dbb12
fix: lint error
xavidop Dec 30, 2023
77e7581
feat: search working
xavidop Dec 30, 2023
cea171d
feat: adding snippet
xavidop Dec 30, 2023
56926e8
feat: serving config
xavidop Dec 31, 2023
1d8f1ea
Merge branch 'master' into xavier/datastores
xavidop Jan 4, 2024
c1eabc0
Merge branch 'master' into xavier/datastores
xavidop Jan 14, 2024
2c8adf2
feat: mod tidy
xavidop Jan 14, 2024
01fa099
feat: datastore client
xavidop Jan 14, 2024
191595e
feat: delete datastore, search suings names and document subcommand
xavidop Jan 14, 2024
e217089
feat: document functions
xavidop Jan 14, 2024
d1c2447
feat: list documents by filter
xavidop Jan 14, 2024
3980f89
Merge branch 'master' into xavier/datastores
xavidop Jan 18, 2024
5223be1
Merge branch 'master' into xavier/datastores
xavidop Jan 19, 2024
8b0f11d
Merge branch 'master' into xavier/datastores
xavidop Jan 30, 2024
c65d454
Merge branch 'master' into xavier/datastores
xavidop Feb 13, 2024
7829c3f
feat: upgrade libs
xavidop Feb 15, 2024
ed4d97e
Merge branch 'master' into xavier/datastores
xavidop Mar 8, 2024
7b353b8
Merge branch 'master' into xavier/datastores
xavidop Mar 15, 2024
7574934
feat: upgrade lib
xavidop Mar 15, 2024
c16b85d
Merge branch 'master' into xavier/datastores
xavidop Apr 1, 2024
77d875c
Merge branch 'master' into xavier/datastores
xavidop Apr 24, 2024
34fa2e6
fix: update goreleaser, removed fig
xavidop Apr 24, 2024
74805ec
fix: build
xavidop Apr 24, 2024
d33ac05
Merge branch 'master' into xavier/datastores
xavidop May 16, 2024
4fd0b0c
feat: upgrade lib and coderabbit config
xavidop May 16, 2024
7473634
feat: conifg
xavidop May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .coderabbit.yaml
@@ -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
28 changes: 0 additions & 28 deletions .github/workflows/fig.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .goreleaser.yml
Expand Up @@ -279,7 +279,7 @@ brews:
- repository:
owner: xavidop
name: homebrew-tap
folder: Formula
directory: Formula
name: cxcli
homepage: 'https://cxcli.xavidop.me'
description: 'The missing CLI for your Dialogflow CX projects'
Expand Down
26 changes: 26 additions & 0 deletions .vscode/launch.json
Expand Up @@ -430,5 +430,31 @@
"generator", "delete", "my-generator", "--agent-name", "test-agent", "--project-id", "test-cx-346408", "--location-id", "us-central1", "--credentials", "credentials.json"
]
},
{
"name": "Data store search command",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/main.go",
"env": {
"ENV": "development"
},
"args": [
"datastore", "search", "cxcli", "--project-id", "test-cx-346408", "--location-id", "global", "--credentials", "credentials.json", "--query", "cxcli"
]
},
{
"name": "Data store delete command",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/main.go",
"env": {
"ENV": "development"
},
"args": [
"datastore", "delete", "gengar", "--project-id", "test-cx-346408", "--location-id", "global", "--credentials", "credentials.json"
]
},
]
}
35 changes: 35 additions & 0 deletions cmd/datastore/datastore.go
@@ -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)
}
50 changes: 50 additions & 0 deletions cmd/datastore/delete.go
@@ -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(err.Error())
os.Exit(1)
}
Comment on lines +24 to +27
Copy link

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.

- global.Log.Errorf(err.Error())
+ global.Log.Errorf("failed to delete datastore: %v", err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err := datastore.Delete(name, locationID, projectID); err != nil {
global.Log.Errorf(err.Error())
os.Exit(1)
}
if err := datastore.Delete(name, locationID, projectID); err != nil {
global.Log.Errorf("failed to delete datastore: %v", err)
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(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(err.Error())
os.Exit(1)
}

}
30 changes: 30 additions & 0 deletions cmd/datastore/document/document.go
@@ -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)
}
56 changes: 56 additions & 0 deletions cmd/datastore/search.go
@@ -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)
Comment on lines +25 to +27
Copy link

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.

- global.Log.Errorf(err.Error())
+ global.Log.Errorf("failed to search datastore: %v", err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err := datastore.Search(name, locationID, projectID, query); err != nil {
global.Log.Errorf(err.Error())
os.Exit(1)
if err := datastore.Search(name, locationID, projectID, query); err != nil {
global.Log.Errorf("failed to search datastore: %v", err)
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)
}

}
3 changes: 3 additions & 0 deletions cmd/root.go
Expand Up @@ -8,6 +8,7 @@ import (
cobracompletefig "github.com/withfig/autocomplete-tools/integrations/cobra"
cmdagent "github.com/xavidop/dialogflow-cx-cli/cmd/agent"
"github.com/xavidop/dialogflow-cx-cli/cmd/cmdutils"
cmddatastore "github.com/xavidop/dialogflow-cx-cli/cmd/datastore"
cmdentitytype "github.com/xavidop/dialogflow-cx-cli/cmd/entitytype"
environmentCmd "github.com/xavidop/dialogflow-cx-cli/cmd/environment"
cmdflow "github.com/xavidop/dialogflow-cx-cli/cmd/flow"
Expand Down Expand Up @@ -72,6 +73,8 @@ func init() {
cmdflow.Register(rootCmd)
cmdflowversion.Register(rootCmd)
cmdgenerator.Register(rootCmd)
cmddatastore.Register(rootCmd)

rootCmd.AddCommand(cobracompletefig.CreateCompletionSpecCommand())

// Add the subcommands
Expand Down
1 change: 1 addition & 0 deletions docs/docs/cmd/cxcli.md
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands
* [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands

* [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
Expand Down
28 changes: 28 additions & 0 deletions docs/docs/cmd/cxcli_datastore.md
@@ -0,0 +1,28 @@
# cxcli datastore

Actions on datastore commands

```
cxcli datastore [flags]
```
Comment on lines +5 to +7
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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

30 changes: 30 additions & 0 deletions docs/docs/cmd/cxcli_datastore_search.md
@@ -0,0 +1,30 @@
# cxcli datastore search

search in a datastore

```
Copy link

Choose a reason for hiding this comment

The 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

```
Copy link

Choose a reason for hiding this comment

The 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

```
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands
* [cxcli datastore](/cmd/cxcli_datastore/) - Actions on datastore commands


31 changes: 31 additions & 0 deletions docs/docs/datastores/introduction.md
@@ -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).