For a third-party application to be able to get the history of messages and also send one, this SDK has to be implemented. Here are the steps to follow;
XendBridge Chat SDK provides only two distinct functions. GetMessageHistory and SendMessage.
The getMessageHistory takes the three arguments which are a public key(string), dispute reference(string), and a function called getAllChats.
getAllChats is a function that must be called as an argument in both getMessageHistory and sendMessage. It automatically fetches the history for you after a message is being sent or when an initial connection to the hub is made.
//implement a better and safer way for getting the following valuesconstdisputeRef="AdhdfoGjfo8jorp";constpublicKey="XP_34984hfhsdksofhs";constgetHistory=async () => {awaitgetMessageHistory(disputeRef, publicKey, getAllChats);};//call when connected to applicationgetHistory();
The sendMessage takes three arguments as well, being an object called ChatHubAddCommentModel which has props of email address, comment, sent by, recipient, base64Attachment, dispute reference, and sent at. The other arguments are the public key and the function getAllChats.
//implement a better and safer way for getting the following valuesconstdisputeRef="AdhdfoGjfo8jorp";constpublicKey="XP_34984hfhsdksofhs";let ChatHubAddCommentModel = { EmailAddress:"youruseremailaddress@domain.com", Comment: comment,//the user's message from the client side SentBy:2,//this is always 2 representing the third party user Recipient:1,//this is always 1 representing all entities involved Base64Attachment:"",//this is the image in base64 format DisputeReference: disputeRef,//the unique dispute reference SentAt:newDate().toISOString() //this is the time in timestamp}//call when user hits the send button on the UIsendMessage(ChatHubAddCommentModel, publicKey, getAllChats);