-
Notifications
You must be signed in to change notification settings - Fork 19
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(push_notification): add pushprovider update and test #92
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package push | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
stream_chat "github.com/GetStream/stream-chat-go/v5" | ||
"github.com/GetStream/stream-cli/pkg/config" | ||
"github.com/GetStream/stream-cli/pkg/utils" | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmds() []*cobra.Command { | ||
return []*cobra.Command{ | ||
updateCmd(), | ||
testCmd(), | ||
} | ||
} | ||
|
||
func updateCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "upsert-pushprovider --properties [raw-json]", | ||
Short: "Create or updates a push provider", | ||
Long: ` | ||
The "--properties" parameter expects a raw json string that can be | ||
unmarshalled into a stream_chat.PushProvider object on the Go SDK side. | ||
See the example section. | ||
Available properties: | ||
type | ||
name | ||
description | ||
disabled_at | ||
disabled_reason | ||
|
||
apn_auth_key | ||
apn_key_id | ||
apn_team_id | ||
apn_topic | ||
|
||
firebase_notification_template | ||
firebase_apn_template | ||
firebase_credentials | ||
|
||
huawei_app_id | ||
huawei_app_secret | ||
|
||
xiaomi_package_name | ||
xiaomi_app_secret | ||
`, | ||
Example: heredoc.Doc(` | ||
# Setting up an APN push provider | ||
$ stream-cli chat upsert-pushprovider --properties "{'type': 'apn', 'name': 'staging', 'apn_auth_key': 'key', 'apn_key_id': 'id', 'apn_topic': 'topic', 'apn_team_id': 'id'}" | ||
|
||
# Setting up a Firebase push provider | ||
$ stream-cli chat upsert-pushprovider --properties "{'type': 'firebase', 'name': 'staging', 'firebase_credentials': 'credentials'}" | ||
|
||
# Setting up a Huawei push provider | ||
$ stream-cli chat upsert-pushprovider --properties "{'type': 'huawei', 'name': 'staging', 'huawei_app_id': 'id', 'huawei_app_secret': 'secret'}" | ||
|
||
# Setting up a Xiaomi push provider | ||
$ stream-cli chat upsert-pushprovider --properties "{'type': 'xiaomi', 'name': 'staging', 'xiaomi_package_name': 'name', 'xiaomi_app_secret': 'secret'}" | ||
`), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
c, err := config.GetConfig(cmd).GetClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
prop, _ := cmd.Flags().GetString("properties") | ||
|
||
var p stream_chat.PushProvider | ||
err = json.Unmarshal([]byte(prop), &p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.UpsertPushProvider(cmd.Context(), &p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd.Println("Successfully updated push provider.") | ||
return nil | ||
}, | ||
} | ||
|
||
fl := cmd.Flags() | ||
fl.StringP("properties", "p", "", "[required] Raw json properties to send to the backend") | ||
_ = cmd.MarkFlagRequired("properties") | ||
|
||
return cmd | ||
} | ||
|
||
func testCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "test-push --message-id [string]" + | ||
" --apn-template [string]" + | ||
" --firebase-template [string]" + | ||
" --firebase-data-template [string]" + | ||
" --skip-devices [true|false]" + | ||
" --push-provider-name [string]" + | ||
" --push-provider-type [string]" + | ||
" --user-id [string]" + | ||
" --output-format [json|tree]", | ||
Short: "Test push notifications", | ||
Example: heredoc.Doc(` | ||
# A test push notification for a certain message id | ||
$ stream-cli chat test-push --message-id msgid --user-id id --skip-devices true | ||
`), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
c, err := config.GetConfig(cmd).GetClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msgID, _ := cmd.Flags().GetString("message-id") | ||
skipDevices, _ := cmd.Flags().GetBool("skip-devices") | ||
pushProviderName, _ := cmd.Flags().GetString("push-provider-name") | ||
pushProviderType, _ := cmd.Flags().GetString("push-provider-type") | ||
userID, _ := cmd.Flags().GetString("user-id") | ||
|
||
p := &stream_chat.CheckPushRequest{ | ||
MessageID: msgID, | ||
SkipDevices: &skipDevices, | ||
PushProviderName: pushProviderName, | ||
PushProviderType: pushProviderType, | ||
UserID: userID, | ||
} | ||
|
||
resp, err := c.CheckPush(cmd.Context(), p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return utils.PrintObject(cmd, resp) | ||
}, | ||
} | ||
|
||
fl := cmd.Flags() | ||
fl.String("message-id", "", "[optional] Message id to test") | ||
fl.Bool("skip-devices", false, "[optional] Whether to notify devices") | ||
fl.String("push-provider-name", "", "[optional] Push provider name to use") | ||
fl.String("push-provider-type", "", "[optional] Push provider type to use") | ||
fl.String("user-id", "", "[optional] User id to initiate the test") | ||
fl.StringP("output-format", "o", "json", "[optional] Output format. Can be json or tree") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package push | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/GetStream/stream-cli/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPushTest(t *testing.T) { | ||
cmd := test.GetRootCmdWithSubCommands(NewCmds()...) | ||
ch := test.InitChannel(t) | ||
u := test.CreateUser() | ||
msgID := test.CreateMessage(ch, u) | ||
t.Cleanup(func() { | ||
test.DeleteMessage(msgID) | ||
test.DeleteChannel(ch) | ||
test.DeleteUser(u) | ||
}) | ||
|
||
cmd.SetArgs([]string{"test-push", "--message-id", msgID, "--user-id", u, "--skip-devices", "true"}) | ||
_, err := cmd.ExecuteC() | ||
require.NoError(t, err) | ||
require.Contains(t, cmd.OutOrStdout().(*bytes.Buffer).String(), msgID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For v2 we have:
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.
I'll need this PR to be merged first: GetStream/stream-chat-go#218
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.
added these 3
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.
we can still provide
firebase_apn_template
andfirebase_notification_template
. why did you drop them?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.
from where? it's there
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.
himm, it wasn't there but it was a commit diff I guess. Looks fine