package com.wecloud.im.sdk.sample;

import com.alibaba.fastjson.JSONObject;
import com.wecloud.im.sdk.WecloudIm;
import com.wecloud.im.sdk.WecloudImClientBuilder;
import com.wecloud.im.sdk.model.ConversationExt;
import com.wecloud.im.sdk.model.SingleUserNotification;
import com.wecloud.im.sdk.model.message.WecloudImBaseMessage;

/**
 * 发布单聊消息
 * @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 s = "{\"fromUserId\":1526928068558675968,\"userName\":\"温枝达\",\"headPortrait\":\"https://xiaohudou.obs.cn-south-1.myhuaweicloud.com/test/62907630993254d611b016f5.min.jpg\",\"type\":\"501\",\"attrs\":{\"fromUserId\":1526928068558675968,\"userName\":\"温枝达\",\"headPortrait\":\"https://xiaohudou.obs.cn-south-1.myhuaweicloud.com/test/62907630993254d611b016f5.min.jpg\",\"type\":\"501\"}}";

        WecloudImBaseMessage message = JSONObject.parseObject(s, WecloudImBaseMessage.class);
        ConversationExt conversationExt = new ConversationExt();
        conversationExt.setName("小虎通知");

        SingleUserNotification singleUserNotification =
                SingleUserNotification.builder()
                        .fromUserId("888888").toUserIds("1527241923595841536")
                        .content(JSONObject.toJSONString(message))
                        .messageType("502")
                        .conversationExt(conversationExt)
                        .persisted(true)
                        .pushContent(null)
                        .build();

        im.singleUserNotification(singleUserNotification);

    }


}
