Hi community!
We’ve recently moved over to SendBird. Our RN app is using GiftedChat, I found a lot of questions on Stackoverflow regarding using SendBird with the react-native-gifted-chat component. The helper below will take your SendBird messages and format for GiftedChat.
Note: For the onSend method, make sure to deconstruct the array and only send over the text value, otherwise SendBird throws an error:
onSend={([message]) => sendMessage(message.text)}
Hope it’s helpful
Cheers,
David
/**
* SendBird > GiftedChat Formatter
* @param {Object} messages SendBird messages object
* @param {string} messageId Message ID
* @param {Object} _sender Sender object
* @param {string} message Message text
* @param {string} createdAt Date of message set as moment()
* @returns {Object} Message formatted for GiftedChat
*/
export const formatMessage = ({ messageId, _sender, message, createdAt }) => {
return message = {
_id: messageId?.toString(), // Fix: GiftedChat keyExtractor Bug
text: message,
createdAt: moment(createdAt),
user: {
_id: _sender?.userId,
name: _sender?.nickname
}
};
}