-
Notifications
You must be signed in to change notification settings - Fork 32
feat: Implement Message Updates, Deletes, and Appends #697
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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,114 @@ | ||
| package ably_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/ably/ably-go/ably" | ||
| ) | ||
|
|
||
| // Example demonstrating how to publish a message and get its serial | ||
| func ExampleRESTChannel_PublishWithResult() { | ||
| client, err := ably.NewREST(ably.WithKey("xxx:xxx")) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| channel := client.Channels.Get("example-channel") | ||
|
|
||
| // Publish a message and get its serial | ||
| result, err := channel.PublishWithResult(context.Background(), "event-name", "message data") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| if result.Serial == nil { | ||
| fmt.Println("Message published but serial not available (discarded by conflation)") | ||
| return | ||
| } | ||
| fmt.Printf("Message published with serial: %s\n", *result.Serial) | ||
| } | ||
|
|
||
| // Example demonstrating how to update a message | ||
| func ExampleRESTChannel_UpdateMessage() { | ||
| client, err := ably.NewREST(ably.WithKey("xxx:xxx")) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| channel := client.Channels.Get("example-channel") | ||
|
|
||
| // First publish a message to get its serial | ||
| result, err := channel.PublishWithResult(context.Background(), "event", "initial data") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| if result.Serial == nil { | ||
| fmt.Println("Message published but serial not available (discarded by conflation)") | ||
| return | ||
| } | ||
|
|
||
| // Update the message | ||
| msg := &ably.Message{ | ||
| Serial: *result.Serial, | ||
| Data: "updated data", | ||
| } | ||
|
|
||
| updateResult, err := channel.UpdateMessage( | ||
| context.Background(), | ||
| msg, | ||
| ably.UpdateWithDescription("Fixed typo"), | ||
| ably.UpdateWithMetadata(map[string]string{"editor": "alice"}), | ||
| ) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
|
lmars marked this conversation as resolved.
|
||
| if updateResult.VersionSerial == nil { | ||
| fmt.Println("Message updated but version serial not available (superseded)") | ||
| return | ||
| } | ||
| fmt.Printf("Message updated with version serial: %s\n", *updateResult.VersionSerial) | ||
| } | ||
|
|
||
| // Example demonstrating async message append for AI streaming | ||
| func ExampleRealtimeChannel_AppendMessageAsync() { | ||
| client, err := ably.NewRealtime(ably.WithKey("xxx:xxx")) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| channel := client.Channels.Get("chat-channel") | ||
|
|
||
| // Publish initial message | ||
| result, err := channel.PublishWithResult(context.Background(), "ai-response", "The answer is") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| if result.Serial == nil { | ||
| fmt.Println("Message published but serial not available (discarded by conflation)") | ||
| return | ||
| } | ||
|
|
||
| // Stream tokens asynchronously without blocking | ||
| tokens := []string{" 42", ".", " This", " is", " the", " answer."} | ||
| for _, token := range tokens { | ||
| msg := &ably.Message{ | ||
| Serial: *result.Serial, | ||
| Data: token, | ||
| } | ||
| // Non-blocking append - critical for AI streaming | ||
| err := channel.AppendMessageAsync(msg, func(r *ably.UpdateDeleteResult, err error) { | ||
| if err != nil { | ||
| fmt.Printf("Append failed: %v\n", err) | ||
| } | ||
| }) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| fmt.Println("All tokens queued for append") | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.