sendMessage static method
Implementation
static Future<Response> sendMessage(
String message, String title, MessageType type) async {
final pref = await SharedPreferences.getInstance();
//Message request model is needed to ensure that the request is send correctly and recollects all the data needed
MessageRequest request = MessageRequest(
type: type.name,
data: MessageRequestData(message: message, title: title),
metadata: MessageRequestMetadata(idTemp: const Uuid().v4()),
createdAt: DateTime.now().toUtc().millisecondsSinceEpoch,
senderId: pref.getString(IdentifierType.userId.name),
sessionUuid: pref.getString(IdentifierType.sessionId.name),
recipinetId: "HOOK",
integrationId: pref.getString(IdentifierType.integrationId.name));
//Serializing the data as Json
var encoded = request.toJson();
//Waiting for response while is sent as an Http Post
var response = await ApiManager.post(
'${SocketUrls.baseBrokerEndpoint}${SocketUrls.sendMessageEndpoint}',
body: jsonEncode(encoded));
return response;
}