How to get information in Rongyun?

problem description

the chat room function needs to be implemented in the vue project. Fuyun is selected. Individuals write some APIs (initialization, connection, monitoring, etc.) in the official website documents in mounted, store appkey, userid and token in data, and then some custom function is defined in methods, such as sending messages. Now the messages are sent successfully.
[question]: how do I receive messages?

the environmental background of the problems and what methods you have tried

I see that the following method is provided on the official website to describe the received message, but I print the data in the onReceived () method, but the relevant information is not printed on the console.

// 
RongIMClient.setOnReceiveMessageListener({
    // 
    onReceived: function(message) {
        console.log("message-->",message)
        ...
    }
})

related codes

data(){
    return {
        userId: "key001"
        appkey: "xxx",
        token: "xxxxx"
    }
},
mounted(){ //
    ...
    // 
    RongIMClient.setOnReceiveMessageListener({
        // 
        onReceived: function(message) {
            console.log("message-->",message)
            ...
        }
    })
    ...
},
methods:{
    ... //
    
    sendTextMessage (textContent) {
      let msg = new RongIMLib.TextMessage({content: textContent, extra:""});
      let conversationtype = RongIMLib.ConversationType.PRIVATE; // 
      let targetId = "doctor001"; //  Id
      
      RongIMClient.getInstance().sendMessage(conversationtype, targetId, msg, {
      
        onSuccess: function (message) {
          console.log("Send successfully");
        },
        
        onError: function (errorCode,message) {
         ... //
        }
        
      });
    }
}

what result do you expect? What is the error message actually seen?

console printed information:



Connect successfully.key001
Send successfully

read the document for yourself, but I don"t understand how to get the reply list. It is said in the document to get a single chat history message, but isn"t there a function that listens to and receives messages before? Why do you need another getHistoryMessages?
[looking forward to results]: please do me a favor and explain a few questions for me by the way:
1. Monitoring and receiving messages are not printed in the setOnReceiveMessageListener, console. How to print this received data
2, the difference between setOnReceiveMessageListener () and getHistoryMessages ()
Thank you in advance ~

Nov.03,2021

setOnReceiveMessageListener, receives real-time messages, which can only be monitored when another person sends you a message. If you want to see the messages sent earlier, you need to obtain historical sessions

.
Menu