HistoricalMessaging not working in agora-react-native-rtm": "^1.2.2-alpha.3" Version
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
could you pls provide a full cURL copy of your request?
Maybe you should be add listener after engine created?
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]
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 If you got any solution about get messgae history then kindly share with me