package com.wecloud.im.sdk.sample;

import java.util.Date;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;

import com.wecloud.im.sdk.WecloudIm;
import com.wecloud.im.sdk.WecloudImClientBuilder;
import com.wecloud.im.sdk.model.PrivateChatMessage;
import com.wecloud.im.sdk.model.message.TextMessage;

/**
 * 发布单聊消息
 * @Author luozh
 * @Date 2022年05月06日 01:37:29
 * @Version 1.0
 */
public class PublishPrivateChatMessageSample {

    public static void main(String[] args) {
//        WecloudIm im = new WecloudImClientBuilder().build("http://139.159.136.86:8082",
//                "QizKVHcILRWp6Td2",
//                "287d04828099fb7de871e9dda845fa8b6b2302faf2ab3737");
        WecloudIm im = new WecloudImClientBuilder().build("http://127.0.0.1:8082",
                "QizKVHcILRWp6Td2",
                "287d04828099fb7de871e9dda845fa8b6b2302faf2ab3737");

        String senderId = "1512322637488148480";
        String toGroupIds = "1513691265777217536";
        String messageType = "-1";

        TextMessage textMessage = new TextMessage();
        textMessage.setText("这是text消息测试: " + DateUtil.formatDateTime(new Date()));

        boolean silent = true;
        PrivateChatMessage privateChatMessage = new PrivateChatMessage();
        privateChatMessage.setFromUserId(senderId);
        privateChatMessage.setToUserIds(toGroupIds);
        privateChatMessage.setMessageType(messageType);
        privateChatMessage.setContent(JSONUtil.toJsonStr(textMessage));
        privateChatMessage.setPushContent("");
        privateChatMessage.setIncludeSender(false);
        privateChatMessage.setPersisted(true);
        privateChatMessage.setSilent(silent);
        Boolean result = im.publishPrivateMessage(privateChatMessage);
    }


}
