Using Notification Factory
Este endpoint permite crear nuevas notificaciones para que puedan ser enviadas a través del servicio de campañas usando el uuid del mensaje recién creado, este endpoint permite una amplia configuración de los mensajes. Debido a limitaciones técnicas que poseen sistemas operativos Android y Ios, hay que tener cuidado con los elementos externos como las imágenes, por lo que es importante probar en un equipo de pruebas antes de realizar un envío masivo.
Endpoint
Headers
Key | Value | Description |
---|---|---|
Content-Type | application/json | |
Authorization | Bearer LVwuk3_oug0D6... | access_token obtained in Atenea |
Url
Method: POST
URL: https://api.trust.lat/message-persistance/api/v1/factory
Recuerda que para utilizar este endpoint es necesario un access token obtenido en el servicio Atenea
Body
{
"notification_version": "trust_notifications_v1",
"notification_type": "notification",
"data": {
"title": "titulo prueba",
"message": "body prueba",
"media_url": "https://.google.cl/photo.svg",
"action_color": "x0x0000x0"
},
"buttons": {
"button_1": {
"action": "https://www.google.cl",
"color": "#ff00ff",
"text": "Ir al sitio",
"type": "url"
},
"button_2": {
"action": "https://www.google.cl",
"color": "#ff00ff",
"text": "Ir al sitio",
"type": "url"
}
},
"config": {
"priority": "normal",
"persistent": true,
"cancelable": false,
"play_time": 1,
"open_app" : true
},
"values": [],
"metadata": {
"reactions": [
"smile", "blush", "joy"
]
}
}
El campo notification_type indica el tipo de notificación que se desea crear pudiendo ser de notification, dialog, video o banner.
Field | Type | Required | Values | Examples | Comments |
---|---|---|---|---|---|
notification_version | String | true | [trust_notifications_v1] | trust_notifications_v1 | |
notification_type | String | true | [notification, dialog, video, banner] | notification | |
values | Array | true | [] | Must be a empty array |
Data
Este campo configura el contenido principal del mensaje, tener cuidado con las imagenes/videos y los colores. Imagenes: Deben ser https y accesible desde cualquier red, formatos permitidos .png y .jpg. Videos: Deben ser https y accesible desde cualquier red, formatos permitidos .mp4 y deben tener un peso ligero para evitar problemas de lentitud al mostrar el video. Color: Precaución con el formato, enviar un color en formato incorrecto causa problemas al mostrar la notificacion, formatos soportado RGB hexadecimal sin transparencia.
Field | Type | Required | Default | Comments | Examples |
---|---|---|---|---|---|
title | String | true | Title of message | ||
message | String | true | Body of message | ||
media_url | String, Url | true | Must be video o image url with https | https://trust-assets.s3.amazonaws.com/enrollment/dialogo_covid.png | |
action_color | String, Color | true | Color of buttons | #9E2626 |
Buttons
Define los botones que se mostrarán en los mensajes, por ahora solo se utilizaran button_1 y button_2 siendo este último opcional
Field | Type | Required | Default | Values | Comments | Examples |
---|---|---|---|---|---|---|
action | String, Url | true | Only 'high' or 'normal' | https://google.cl | ||
color | String, Color | false | RGB Hex color | #9E2626 | ||
text | String | true | Presione Aquí | |||
type | type | true | [url, call, mail] | url |
Config
Field | Type | Required | Default | Comments | Examples |
---|---|---|---|---|---|
priority | String | false | high | Only 'high' or 'normal' | high |
persistent | Boolean | false | false | true | |
cancelable | Boolean | false | false | false | |
play_time | Int | false | 0 | 5 | |
open_app | Boolean | false | None | Field that indicates whether the "open_app" button is available. It only works for notification type messages. | true |
Metadata
Field | Type | Required | Default | Comments | Examples |
---|---|---|---|---|---|
reactions | Array of strings | false | None | Array of strings than contains the "reaction_name" of emojis. Max 5, min 1 | reactions: [ "smile", "blush", "joy" ] |
Revisar la lista de emojis permitidos para este endpoint
Code Examples
- Curl
- JavaScript
- Python
curl --location --request POST 'https://api.trust.lat/message-persistance/api/v1/factory' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer LVwuk3_oug0D6...' \
--data-raw '{
"notification_version": "trust_notifications_v1",
"notification_type": "notification",
"data": {
"title": "titulo prueba",
"message": "body prueba",
"media_url": "https://.google.cl/photo.svg",
"action_color": "x0x0000x0"
},
"buttons": {
"button_1": {
"action": "https://www.google.cl",
"color": "#ff00ff",
"text": "Ir al sitio",
"type": "url"
},
"button_2": {
"action": "https://www.google.cl",
"color": "#ff00ff",
"text": "Ir al sitio",
"type": "url"
}
},
"config": {
"priority": "normal",
"persistent": true,
"cancelable": false,
"play_time": 1,
"open_app": true
},
"values": [],
"metadata": {
"reactions": [
"smile", "heart_eyes", "heart_eyes", "heart_eyes", "heart_eyes"
]
},
}'
import requests
url = "https://api.trust.lat/message-persistance/api/v1/factory"
payload = "{\n \"notification_version\": \"trust_notifications_v1\",\n \"notification_type\": \"notification\",\n \"data\": {\n \"title\": \"titulo prueba\",\n \"message\": \"body prueba\",\n \"media_url\": \"https://.google.cl/photo.svg\",\n \"action_color\": \"x0x0000x0\"\n },\n \"buttons\": {\n \"button_1\": {\n \"action\": \"https://www.google.cl\",\n \"color\": \"#ff00ff\",\n \"text\": \"Ir al sitio\",\n \"type\": \"url\"\n },\n \"button_2\": {\n \"action\": \"https://www.google.cl\",\n \"color\": \"#ff00ff\",\n \"text\": \"Ir al sitio\",\n \"type\": \"url\"\n }\n },\n \"config\": {\n \"priority\": \"normal\",\n \"persistent\": true,\n \"cancelable\": false,\n \"play_time\": 1,\n \"open_app\": true\n },\n \"values\": [],\n \"metadata\": {\n \"reactions\": [\n \"smile\", \"blush\", \"joy\"\n ]\n }"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer LVwuk3_oug0D...'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
var axios = require('axios');
var data = JSON.stringify({"notification_version":"trust_notifications_v1","notification_type":"notification","data":{"title":"titulo prueba","message":"body prueba","media_url":"https://.google.cl/photo.svg","action_color":"x0x0000x0"},"buttons":{"button_1":{"action":"https://www.google.cl","color":"#ff00ff","text":"Ir al sitio","type":"url"},"button_2":{"action":"https://www.google.cl","color":"#ff00ff","text":"Ir al sitio","type":"url"}},"config":{"priority":"normal","persistent":true,"cancelable":false,"play_time":1,"open_app":true},"values":[]},"metadata":{"reactions":["smile","blush","joy"]});
var config = {
method: 'post',
url: 'https://api.trust.lat/message-persistance/api/v1/factory',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer LVwuk3_oug0D6...'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Responses
HTTP Code: 201 Created
{
"code": 201,
"resource": "message",
"data": {
"id": 1,
"uuid": "bdcaa73a-61de...",
"custom_notification": {
"priority": "normal",
"data": {
"type": "notification",
"reactions": "[{\"reaction_name\":\"smile\",\"emoji_hex\":\"U+1F604\"},{\"reaction_name\":\"heart_eyes\",\"emoji_hex\":\"U+1F60D\"},{\"reaction_name\":\"blush\",\"emoji_hex\":\"U+1F60A\"}]",
"notificationBody": "{\"text_title\":\"titulo prueba\",\"text_body\":\"body prueba\",\"image_url\":\"https://.google.cl/photo.svg\",\"isPersistent\":true,\"isCancelable\":false,\"min_play_time\":\"1\",\"buttons\":[{\"action\":\"none\",\"color\":\"#000000\",\"text\":\"none\",\"type\":\"open_app\"},{\"action\":\"https://www.google.cl\",\"color\":\"#ff00ff\",\"text\":\"Ir al sitio\",\"type\":\"url\"},{\"action\":\"https://www.google.cl\",\"color\":\"#ff00ff\",\"text\":\"Ir al sitio\",\"type\":\"url\"}]}"
},
"apns": {
"payload": {
"aps": {
"sound": "default",
"category": "url-url",
"mutable-content": 1,
"alert": {
"title": "titulo prueba",
"body": "body prueba"
},
"badge": 1
},
"data": {
"type": "notification",
"reactions": "[{\"reaction_name\":\"smile\",\"emoji_hex\":\"U+1F604\"},{\"reaction_name\":\"heart_eyes\",\"emoji_hex\":\"U+1F60D\"},{\"reaction_name\":\"blush\",\"emoji_hex\":\"U+1F60A\"}]",
"notificationBody": "{\"text_title\":\"titulo prueba\",\"text_body\":\"body prueba\",\"image_url\":\"https://.google.cl/photo.svg\",\"isPersistent\":true,\"isCancelable\":false,\"min_play_time\":\"1\",\"buttons\":[{\"action\":\"none\",\"color\":\"#000000\",\"text\":\"none\",\"type\":\"open_app\"},{\"action\":\"https://www.google.cl\",\"color\":\"#ff00ff\",\"text\":\"Ir al sitio\",\"type\":\"url\"},{\"action\":\"https://www.google.cl\",\"color\":\"#ff00ff\",\"text\":\"Ir al sitio\",\"type\":\"url\"}]}"
}
}
}
},
"values": [],
"created_at": "2020-05-26T22:21:39.701Z",
"updated_at": "2020-05-26T22:21:39.701Z",
"status": true,
"type_notification": "trust_notification",
"disposable": false,
"factory_message": {
"type": "notification",
"data": {
"title": "titulo test 4",
"message": "body prueba 4",
"media_url": "https://.google.cl/photo.svg",
"action_color": "#348dfc"
},
"config": {
"priority": "normal",
"persistent": true,
"cancelable": true,
"play_time": 1,
"portrait": true,
"auto_play": true,
"is_sound": true,
"open_app": true
},
"buttons": {
"button_1": {
"action": "https://www.google.cl",
"color": "#348dfc",
"text": "Ir al sitio",
"type": "url"
},
"button_2": {
"action": "https://www.google.cl",
"color": "#348dfc",
"text": "Ir al sitio",
"type": "url"
}
},
"metadata": {
"reactions": [
"smile",
"heart_eyes",
"blush"
]
}
},
"company_uuid": null
},
"message": "Created"
}
HTTP Code: 422 Unprocessable Entity
{
"code": 422,
"resource": "message",
"message": "Fail",
"errors": "invalid notification_version, only [trust_notifications_v1] are valid"
}
HTTP Code: 422 Unprocessable Entity (reactions errors)
{
"code": 422,
"resource": "message",
"message": "Fail",
"errors": {
"metadata": {
"reactions": [
"Min 1 and no more than 5 reactions are allowed"
]
}
}
}