GetStream / stream-chat-swift

💬 iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
https://getstream.io/chat/sdk/ios/
Other
858 stars 211 forks source link

append to a chat message #2593

Closed paulz closed 1 year ago

paulz commented 1 year ago

Thank you for awesome service, great API and so many clients!

What are you trying to achieve?

We want to update message by appending text to it.

If possible, how can you achieve this currently?

We currently use partial update message API:

https://getstream.io/chat/docs/rest/#messages-updatemessagepartial

but it requires set message text

What would be the better way?

Append to message API

GetStream Environment

GetStream Chat version: 4.3.0 GetStream Chat frameworks: StreamChat, StreamChatSwiftUI iOS version: 16.0 Swift version: 5 Xcode version: 14.2 Device: iPhone

Additional context

polqf commented 1 year ago

Hi @paulz ,

This is in our roadmap, and we should be tackling it soon 🙏

paulz commented 1 year ago

thank you, you rock!

nuno-vieira commented 1 year ago

Hi @paulz!

What do you mean by "appending text"? As of now, you can do that already by using ChatMessageController.editMessage(). You can use the current message text, to append text, example:

let currentMessageText = messageController.message.text
let editedText = currentMessageText + newText
messageController.editMessage(text: editedText)

The only thing not supported yet is appending new attachments, which is in the roadmap.

Can you clarify what you mean by "appending text"?

Best, Nuno

paulz commented 1 year ago

Thank you for looking into this @nuno-vieira !

This is a question/request for backend of StreamChat to allow us to use stream of text to send to chat.

Use case: Our AI bot types a lot of text to a user in the chat. We want user to see bot response appearing in the chat as it being written "in real time".

Currently we either only show bot typing using typing indicator until we get full response, which takes a long time. Or we continuously update last message by appending more text to it and making put request: https://getstream.io/chat/docs/rest/#messages-updatemessagepartial this cause a lot more traffic as we have to send whole body of the message not only appended text.

Ideally what we want is to open an HTTP stream to stream chat and pipe text to update last message. And on the client side (Swift and SwiftUI) web socket to receive that stream and update last message chat bubble.

Does it make sense?

nuno-vieira commented 1 year ago

Hi @paulz!

I see; this is a Backend feature request, then. In this case, it is better if you reach support@getstream.io and explain why you need this new feature 👍

There is also a chance that you might be able to do this already with Custom Events. This doc should be able to help you: https://getstream.io/chat/docs/ios-swift/custom_events/?language=go

You probably can create a custom event and use the message.updated type, to trigger a message update from the websocket connection. This will work if the custom event has the message.updated type and it contains the message object. But I'm not 100% sure if this will work. In any case, support should be able to help you 🙂

Best, Nuno