tencent cloud



Last updated: 2023-07-17 15:18:31


    When sending a message, the user may want to switch to another chat window before finishing the message. The unfinished message can be saved through the setConversationDraft API, so that the user can get back to it through the draftText field of the V2TIMConversation object and finish it.
    1. A conversation draft can contain only text.
    2. A conversation draft will be stored only in the local database and not on the server. Therefore, it cannot be synced across devices and will not be available after the application is uninstalled and reinstalled.

    Setting a Conversation Draft

    Call the setConversationDraft API (Android / iOS and macOS / Windows) to set a conversation draft. If the draftText parameter is empty, the draft is cleared.
    Sample code:
    iOS and macOS
    String conversationID = "conversationID";
    String draftText = "The draft text";
    V2TIMManager.getConversationManager().setConversationDraft(conversationID, draftText, new V2TIMCallback() {
    public void onSuccess() {
    Log.i("imsdk", "success");
    public void onError(int code, String desc) {
    Log.i("imsdk", "failure, code:" + code + ", desc:" + desc);
    NSString *conversationID = @"conversationID";
    NSString *draftText = "The draft text";
    [[V2TIMManager sharedInstance] setConversationDraft:conversationID draftText:draftText succ:^{
    } fail:^(int code, NSString *desc) {
    NSLog(@"failure, code:%d, desc:%@", code, desc);
    class Callback final : public V2TIMCallback {
    using SuccessCallback = std::function<void()>;
    using ErrorCallback = std::function<void(int, const V2TIMString&)>;
    Callback() = default;
    ~Callback() override = default;
    void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
    success_callback_ = std::move(success_callback);
    error_callback_ = std::move(error_callback);
    void OnSuccess() override {
    if (success_callback_) {
    void OnError(int error_code, const V2TIMString& error_message) override {
    if (error_callback_) {
    error_callback_(error_code, error_message);
    SuccessCallback success_callback_;
    ErrorCallback error_callback_;
    V2TIMString conversationID = u8"conversationID";
    V2TIMString draftText = u8"The draft text";
    auto callback = new Callback;
    [=]() {
    // Set the conversation draft successfully
    delete callback;
    [=](int error_code, const V2TIMString& error_message) {
    // Failed to set the conversation draft
    delete callback;
    V2TIMManager::GetInstance()->GetConversationManager()->SetConversationDraft(conversationID, draftText,
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support