Entries
All the data sent by someone to an Inbox is called an Entry. In Threads and Stores, a user must be assigned to the container to send data. In Inboxes, however, anyone who has Inbox ID can send a reply (assuming they have the Bridge URL and Solution ID).
Public Connection
Endpoint provides different ways to connect to a Bridge instance.
-
Using
Endpoint.connect
In this case, a user must provide private key matching the public key registered earlier. This method of connection gives access to all methods provided by the Endpoint.To submit data using private connection use
sendData
:await Endpoint.connection().inbox('INBOX_ID').sendData({
data: serializeObject({
inquiryType: 'newsletter',
answer: 'email@domain.com'
})
}); -
Using
Endpoint.connectPublic
When using "public" connection you don't have to pass a private key. A random private key will be generated for each connection. The public connection provides only the methods related to sending Inbox entries and retrieving public metadata related to the Inbox.To submit data using public connection use
sendDataToInbox
:const publicConnection = await Endpoint.connectPublic({
bridgeUrl: 'BRIDGE_URL',
solutionId: 'SOLUTION_ID'
});
await publicConnection.sendDataToInbox('INBOX_ID', {
data: serializeObject({
inquiryType: 'newsletter',
answer: 'email@domain.com'
})
});
In both cases, you have to pass required Bridge URL and Solution ID.
If you want to learn more about using public connection with Inboxes check Inbox docs. The following examples include code snippets using private connection but everything also applies to public connection.
Submitting Entries
const entryMessage = 'Example message';
const sentEntry = await Endpoint.connection().inbox('INBOX_ID').sendData({
data: new TextEncoder().encode(entryMessage)
});
Fetching Entries
Fetching the most recent Entries submitted to Inbox:
const entryList = await Endpoint.connection().inbox('INBOX_ID').listEntries();
const parsedEntries = entryList.readItems.map(entry => {
const deserializedData = deserializeObject(entry.data);
return {
...entry,
data: deserializedData
};
});
Note that there is no difference between Entries sent using public connection and the default one.