Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/stream-cli_chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Allows you to interact with your Chat applications
* [stream-cli chat update-channel](stream-cli_chat_update-channel.md) - Update a channel
* [stream-cli chat update-channel-partial](stream-cli_chat_update-channel-partial.md) - Update a channel partially
* [stream-cli chat update-channel-type](stream-cli_chat_update-channel-type.md) - Update channel type
* [stream-cli chat update-message](stream-cli_chat_update-message.md) - Update an existing message
* [stream-cli chat update-message-partial](stream-cli_chat_update-message-partial.md) - Partially update a message
* [stream-cli chat update-user-partial](stream-cli_chat_update-user-partial.md) - Partially update a user
* [stream-cli chat upload-file](stream-cli_chat_upload-file.md) - Upload a file
Expand Down
42 changes: 42 additions & 0 deletions docs/stream-cli_chat_update-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## stream-cli chat update-message

Update an existing message

### Synopsis

Update a message by providing the message ID, user ID, and new message text.
This fully overwrites the message content while preserving metadata.


```
stream-cli chat update-message --message-id [id] --user [user-id] --text [text] [flags]
```

### Examples

```
# Update a message by ID
$ stream-cli chat update-message --message-id msgid-123 --user user123 --text "Updated message text"

```

### Options

```
-h, --help help for update-message
--message-id string [required] ID of the message to update
--text string [required] New message text
--user string [required] User ID performing the update
```

### Options inherited from parent commands

```
--app string [optional] Application name to use as it's defined in the configuration file
--config string [optional] Explicit config file path
```

### SEE ALSO

* [stream-cli chat](stream-cli_chat.md) - Allows you to interact with your Chat applications

7 changes: 4 additions & 3 deletions docs/stream-cli_chat_upload-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ $ stream-cli chat upload-import data.json --mode insert --output-format tree
### Options

```
-h, --help help for upload-import
-m, --mode string [optional] Import mode. Canbe upsert or insert (default "upsert")
-o, --output-format string [optional] Output format. Can be json or tree (default "json")
-h, --help help for upload-import
--lighter-validation-id [optional] allows to pass ! in channel ID
-m, --mode string [optional] Import mode. Canbe upsert or insert (default "upsert")
-o, --output-format string [optional] Output format. Can be json or tree (default "json")
```

### Options inherited from parent commands
Expand Down
6 changes: 3 additions & 3 deletions docs/stream-cli_chat_upsert-pushprovider.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Create or updates a push provider
description
disabled_at
disabled_reason

apn_auth_key
apn_key_id
apn_team_id
Expand All @@ -23,10 +23,10 @@ Create or updates a push provider
firebase_notification_template
firebase_apn_template
firebase_credentials

huawei_app_id
huawei_app_secret

xiaomi_package_name
xiaomi_app_secret

Expand Down
5 changes: 3 additions & 2 deletions docs/stream-cli_chat_validate-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ $ stream-cli chat validate-import data.json
### Options

```
-h, --help help for validate-import
-o, --output-format string [optional] Output format. Can be json or tree (default "json")
-h, --help help for validate-import
--lighter-validation-id [optional] allows to pass ! in channel ID
-o, --output-format string [optional] Output format. Can be json or tree (default "json")
```

### Options inherited from parent commands
Expand Down
51 changes: 51 additions & 0 deletions pkg/cmd/chat/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewCmds() []*cobra.Command {
deleteCmd(),
flagCmd(),
translateCmd(),
updateMessageCmd(),
}
}

Expand Down Expand Up @@ -333,3 +334,53 @@ func translateCmd() *cobra.Command {

return cmd
}

func updateMessageCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update-message --message-id [id] --user [user-id] --text [text]",
Short: "Update an existing message",
Long: heredoc.Doc(`
Update a message by providing the message ID, user ID, and new message text.
This fully overwrites the message content while preserving metadata.
`),
Example: heredoc.Doc(`
# Update a message by ID
$ stream-cli chat update-message --message-id msgid-123 --user user123 --text "Updated message text"
`),
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")
userID, _ := cmd.Flags().GetString("user")
text, _ := cmd.Flags().GetString("text")

updatedMsg := &stream.Message{
ID: msgID,
Text: text,
User: &stream.User{ID: userID},
}

_, err = c.UpdateMessage(cmd.Context(), updatedMsg, msgID)
if err != nil {
return err
}

cmd.Println("Successfully updated message.")
return nil
},
}

fl := cmd.Flags()
fl.String("message-id", "", "[required] ID of the message to update")
fl.String("user", "", "[required] User ID performing the update")
fl.String("text", "", "[required] New message text")

_ = cmd.MarkFlagRequired("message-id")
_ = cmd.MarkFlagRequired("user")
_ = cmd.MarkFlagRequired("text")

return cmd
}
49 changes: 49 additions & 0 deletions pkg/cmd/chat/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package message

import (
"bytes"
"context"
"os"
"regexp"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -153,3 +155,50 @@ func TestTranslateMessage(t *testing.T) {
require.NoError(t, err)
require.Contains(t, cmd.OutOrStdout().(*bytes.Buffer).String(), "szia")
}

func TestUpdateMessage(t *testing.T) {
cmd := test.GetRootCmdWithSubCommands(NewCmds()...)
ch := test.InitChannel(t)
u := test.CreateUser()

t.Cleanup(func() {
test.DeleteChannel(ch)
test.DeleteUser(u)
})

// Step 1: Send original message
cmd.SetArgs([]string{
"send-message",
"-t", "messaging",
"-i", ch,
"-u", u,
"--text", "Original message",
})
_, err := cmd.ExecuteC()
require.NoError(t, err)

// Extract message ID from stdout
out := cmd.OutOrStdout().(*bytes.Buffer).String()
re := regexp.MustCompile(`Message id: \[(.+?)]`)
matches := re.FindStringSubmatch(out)
require.Len(t, matches, 2)
msgID := matches[1]

// Step 2: Update the message
cmd.SetArgs([]string{
"update-message",
"--message-id", msgID,
"--user", u,
"--text", "Updated message text",
})
_, err = cmd.ExecuteC()
require.NoError(t, err)
require.Contains(t, cmd.OutOrStdout().(*bytes.Buffer).String(), "Successfully updated message.")

// Step 3: Fetch and verify the update
client := test.InitClient()
ctx := context.Background()
resp, err := client.GetMessage(ctx, msgID)
require.NoError(t, err)
require.Equal(t, "Updated message text", resp.Message.Text)
}