This tutorial will cover how you can message a contact using FlockOS APIs.
Handling App Installs and Tokens
Before you proceed further, please go through Handling App Installs and Tokens if you haven't already.
To discover and message contacts, we need to call Methods, which we can't do without saving authentication tokens, which is what gets covered in that tutorial.
Discover your contacts' identifier
After installing the app into your own account from the developer dashboard and saving your authentication token, the first thing you need to do is decide which contact to send a message to. Once you've done that you will need that contact's identifier.
We call roster.listContacts to get details about all of our contacts, including their identifiers.
Only the authentication token discovered during app.install is required to call this method.
The response to this method returns an array of PublicProfile objects (an example is shown below). You can retrieve the identifier for the contact from the
id field of this object.
Send a message to the contact
To send a message, you need to call chat.sendMessage. Using your authentication token and the identifier from the previous step, you can easily do this.
The method returns a globally unique identifier for the message in the
uid field. If the message includes an Attachment, the uid can be used to later identify the message when a user clicks on an attachment button, or opens an attachment widget, or takes a FlockML action.