agora-react-native-rtm icon indicating copy to clipboard operation
agora-react-native-rtm copied to clipboard

HistoricalMessaging not working in agora-react-native-rtm": "^1.2.2-alpha.3" Version

Open kuldipp1995 opened this issue 4 years ago • 5 comments

I have added below code but now works for me, I when I'm try to get recent chat list then not getting any messages

Message History EndPoint:- "https://api.agora.io/dev/v2/project/{{appId}}/rtm/message/history/query"

import RtmEngine from 'agora-react-native-rtm';

const APP_ID = '' let engine;

import { EventRegister } from 'react-native-event-listeners'

class AgoraManager {

static loginUserUid = ''

static agoraInit = async(strEmail, strChatToken) => {
    
    arrChatMessages = []

    engine = new RtmEngine();
    loginUserUid = strEmail
    
    engine.on('error', evt => {
        console.log(evt);
    });

    //4.Received Observer
    engine.on('messageReceived', evt => { 
        let {text, ts, peerId} = evt;
        let dictMessage = { user_id: peerId, message: text, msgTimeStamp: ts}
        console.log("Message recievied =>", dictMessage);
        EventRegister.emit('RECEIVE_NEW_MESSAGE', dictMessage)
    });

    //1. Create Client
    await engine.createClient(APP_ID).catch(e => console.log(e));
    
    //2. Login in agora
    await engine.login({uid: loginUserUid, token: strChatToken})

}

static sendMessage = async (dictAgoraPeerMessage) => {
    await engine.sendMessageToPeer(dictAgoraPeerMessage).then((data) => {
        console.log("Send Message With Response =>",data)
    }).catch((err) => {
        console.log("Message Error =>",error)
    })
}

static endChat = async () => {
    await engine.logout().catch(e => console.log(e));
    await engine.destroyClient().catch(e => console.log(e));
};

}

export { AgoraManager };

Chat.js let dictMessage = { 'peerId': this.state.strReceiveUId, 'offline': true, 'text': this.state.strUserMessage.trim(), const {response} = await AgoraManager.sendMessage(dictMessage)

AgoraRTM.m

// sendMessageToPeer RCT_EXPORT_METHOD(sendMessageToPeer: (NSDictionary *) params resolve: (RCTPromiseResolveBlock) resolve reject: (RCTPromiseRejectBlock) reject) { BOOL offline = [params[@"offline"] boolValue]; NSString *text = params[@"text"]; NSString *peerId = params[@"peerId"];

AgoraRtmSendMessageOptions *options = [AgoraRtmSendMessageOptions new];
**[options setEnableHistoricalMessaging:true];**
[options setEnableOfflineMessaging:offline];
AgoraRtmMessage *message = [[AgoraRtmMessage new] initWithText:text];
[[self rtmKit] sendMessage:message toPeer:peerId sendMessageOptions:options completion:^(AgoraRtmSendPeerMessageErrorCode errorCode) {
    if (errorCode == AgoraRtmSendPeerMessageErrorOk) {
        resolve(nil);
    } else {
        reject(@(errorCode).stringValue, @"", nil);
    }
}];

}

Please suggest me any solution for this.

Thank you

kuldipp1995 avatar Apr 08 '21 07:04 kuldipp1995

could you pls provide a full cURL copy of your request?

plutoless avatar Apr 08 '21 07:04 plutoless

Maybe you should be add listener after engine created?

RoJoHub avatar Apr 08 '21 07:04 RoJoHub

could you pls provide a full cURL copy of your request?

https://api.agora.io/dev/v2/project/7fbb032d23784374b7f38163102019ab/rtm/message/history/query

x-agora-token:- 0067fbb032d23784374b7f38163102019abIACP6+OdB7i4TwZq3HjQHJgNoycsH5Acbd1nRc7LIlCMQnmz7I4AAAAAEACNyCbp4fRvYAEA6AMAAAAA

uid:- [email protected]

kuldipp1995 avatar Apr 08 '21 08:04 kuldipp1995

Maybe you should be add listener after engine created?

Yes, we have moved our code as per your suggestion and try the same steps but history messages aren't displaying. Please provide the example link or something of react-native in which Historical Message display.

static agoraInit = async(strEmail, strChatToken) => {

    engine = new RtmEngine();
    loginUserUid = strEmail
    
    engine.on('error', evt => {
        console.log(evt);
    });

    //1. Create Client
    await engine.createClient(APP_ID).catch(e => console.log(e));
    
    //2. Login in agora
    await engine.login({uid: loginUserUid, token: strChatToken})

    //4.Received Observer
    engine.on('messageReceived', evt => { 
        let {text, ts, peerId} = evt;
        let dictMessage = { user_id: peerId, message: text, msgTimeStamp: ts}
        console.log("Message recievied =>", dictMessage);  
        EventRegister.emit('RECEIVE_NEW_MESSAGE', dictMessage)
    });
}

kuldipp1995 avatar Apr 12 '21 07:04 kuldipp1995

@kuldipp1995 If you got any solution about get messgae history then kindly share with me

rehmanalikwanso avatar Mar 07 '23 09:03 rehmanalikwanso