GetMessagesFromConversation return zero messages in message list on Rainbow.CSharp.SDK nuget package
AnsweredHi,
I need to retrieve conversation messages from a particular contact, I have used GetMessagesFromConversation and GetMessagesFromContactId, both are not return any messages ie, count=0 in their message list.
This is the code which I used to retrieve messages:
Rainbow.Contacts contacts = myApp.GetContacts();
String contactID = "xxxxxxxxx"; // Your contact id
contacts.GetContactFromContactIdFromServer(contactID, callback1 =>
{
if (callback1.Result.Success)
{
Contact contact = callback1.Data; // Contact found
Rainbow.Conversations conversations = myApp.GetConversations();
conversations.GetConversationFromContactId(contactID, callback2 =>
{
if (callback2.Result.Success)
{
Conversation convObj = callback2.Data; // List of conversations
Rainbow.InstantMessaging imMsglist = myApp.GetInstantMessaging();
imMsglist.GetMessagesFromConversation(convObj, 3, callback3 =>
{
if (callback2.Result.Success)
{
}
else
{
}
});
}
else
{
// Exception occurs
Exception e = callback2.Result.ExceptionError;
}
});
}
else
{
// Exception occurs
Exception e = callback1.Result.ExceptionError;
}
});
-
Have you tried this example:
https://github.com/Rainbow-CPaaS/Rainbow-CSharp-SDK-Samples/tree/master/InstantMessaging
Using this sample with your accounts do you have still the pb ?
-
Hi Cristophe,
I copied that lines from previous post.
Here below I put my sample code,
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Rainbow.Application myApp = new Rainbow.Application();
myApp.SetApplicationInfo(ConfigurationManager.AppSettings["AppId"].ToString(), ConfigurationManager.AppSettings["AppSecretKey"].ToString());
myApp.SetHostInfo(ConfigurationManager.AppSettings["Hostname"].ToString());
myApp.Login("username", "password", callback =>
{
if (callback.Result.Success)
{
Rainbow.Contacts contacts = myApp.GetContacts();
String contactID = "xxxxxx"; // Your contact id
contacts.GetContactFromContactIdFromServer(contactID, callback1 =>
{
if (callback1.Result.Success)
{
Contact contact = callback1.Data; // Contact found
Rainbow.Conversations conversations = myApp.GetConversations();
conversations.GetConversationFromContactId(contactID, callback2 =>
{
if (callback2.Result.Success)
{
Conversation convObj = callback2.Data; // List of conversations
Rainbow.InstantMessaging imMsglist = myApp.GetInstantMessaging();
imMsglist.GetMessagesFromContactId(contactID, 3, callback3 =>
{
if (callback3.Result.Success)
{
}
else
{}
});
}
else
{
if (callback2.Result.Type == SdkError.SdkErrorType.IncorrectUse)
{
// Bad parameters used
string errMsg = callback2.Result.IncorrectUseError.ErrorMsg;
}
else
{
// Exception occurs
Exception e = callback2.Result.ExceptionError;
}
}
});
}
else
{
if (callback1.Result.Type == SdkError.SdkErrorType.IncorrectUse)
{
// Bad parameters used
string errMsg = callback1.Result.IncorrectUseError.ErrorMsg;
}
else
{
// Exception occurs
Exception e = callback1.Result.ExceptionError;
}
}
});
}
else
{
// A pb occurs
if (callback.Result.Type == SdkError.SdkErrorType.IncorrectUse)
{
// Bad parameter(s) used
string errMsg = callback.Result.IncorrectUseError.ErrorMsg;
}
else
{
// Exception occurs
Exception e = callback.Result.ExceptionError;
}
}
}); -
Hi Sathya,
1) When you login you need to wait the event "ConnectionStateChanged" with a value equal to ConnectionState.Connected before to continue any action
2) You can get messages only wih a contact in your roster. So after
Rainbow.Contacts contacts = myApp.GetContacts();
// One you connection state is Connected
contacts.GetAllContacts(...)
String contactID = "xxxxxx"; // Your contact id
contacts.GetContactFromContactId(contactID) => Must return a non null Contact object
3) As suggested could you first use the SDK Sample with your accountID to check if you retrieve well your messages.
https://github.com/Rainbow-CPaaS/Rainbow-CSharp-SDK-Samples/tree/master/InstantMessaging
Regards,
Christophe
Please sign in to leave a comment.
Comments
9 comments