The Message API aims to cover the Messages part of the REST API documentation. More precisely:
- Get a message
- Get messages
- Get message IDs by timestamp
- Send message
- Import messages
- Get attachment
- List attachments
- Get allowed attachment types
- Suppress message
- Get message status
- Get message receipts
- Get message relationships
The central component for the Message API is the MessageService.
It exposes all the services mentioned above and is accessible from the SymphonyBdk object by calling the messages() method.
For instance:
import com.symphony.bdk.core.MessageService;
public class Example {
public static final String STREAM_ID = "gXFV8vN37dNqjojYS_y2wX___o2KxfmUdA";
public static void main(String[] args) throws Exception {
// Create BDK entry point
final SymphonyBdk bdk = new SymphonyBdk(loadFromClasspath("/config.yaml"));
// Get the MessageService object
final MessageService messageService = bdk.message();
//send a regular message
final V4Message regularMessage = messageService.send(STREAM_ID, "<messageML>Hello, World!</messageML>");
System.out.println("Message sent, id: " + regularMessage.getMessageId());
}
}A more detailed example with all exposed services can be found here.
The Message service also allows you to send messages using templates. So far, we only support FreeMarker templates, but we may add support for other template engines. For instance, if you have the following template file:
<messageML>${message}</messageML>
you will be able to use it when sending message:
final SymphonyBdk bdk = new SymphonyBdk(loadFromClasspath("/config.yaml"));
final V4Message regularMessage = bdk().message().send(streamId, "path/to/template.ftl", Collections.singletonMap("message", "Hello!"));The above will send the message <messageML>Hello!</messageML> as expected.
Please check the FreeMarker documentation
to know more about the data model you can use in templates and about the corresponding object structure you need to pass as parameter.
The template name passed as parameter can be the name of a built-in template (only "simpleMML" available so far), the path to a template file or a URL to a template file. The templates will be looked for in this order:
- in built-in templates
- in the classpath
- in the file system
- lastly as a URL