Skip to content

Message Types

adamant-al edited this page May 28, 2021 · 3 revisions

Chat is essential ADAMANT transaction type.

Chats can be fetched using Chatrooms or Chat transactions. Chatrooms is a convenient endpoint for building messenger app, while Chat transaction is useful for creating bots.

Read more about Chatrooms in AIP 14: Chatrooms API.

Chat Transactions

Chat transaction is of type 8 and contains asset field with chat object:

  • messageencrypted message
  • own_message — nonce
  • type — type of chat message

Chat transaction example:

{
    "transaction": {
        "type": 8,
        "amount": 0,
        "senderId": "U12499126640447739963",
        "senderPublicKey": "e9cafb1e7b403c4cf247c94f73ee4cada367fcc130cb3888219a0ba0633230b6",
        "asset": {
            "chat": {
                "message": "cb682accceef92d7cddaaddb787d1184ab5428",
                "own_message": "e7d8f90ddf7d70efe359c3e4ecfb5ed3802297b248eacbd6",
                "type": 1
            }
        },
        "recipientId": "U15677078342684640219",
        "timestamp": 63228087,
        "signature": "c998be1c44e49be24cbcad71ee5cd4394832302086da259fa819bc38fc29ffe11094ab2b0e9ff301612f52cf5528e1fa9467fc26e6c26ace0f6f1dd39e4df20f"
    }
}

Message Types

Basic Encrypted Messages

Basic Encrypted Message is a simple encrypted message transaction which includes message and own_message. Type of message is 1.

Along with sending a message, Basic Encrypted Message can be used to transfer ADM tokens. Add integer amount of 1/10^8 ADM tokens (1 ADM = 100000000) in transaction object to make a token transfer. In this case message field will be used as a comment for ADM transfer.

Note, transaction fee for Basic Encrypted Message with token transfer is the same as for Token Transfer Transactions type 0, 0.5 ADM.

For additional information refer to AIP 4: Basic Encrypted Messages.

Example:

{
    "success": true,
    "nodeTimestamp": 63653313,
    "transaction": {
        "id": "9175562912139726777",
        "height": 10288885,
        "blockId": "10475460465898092643",
        "type": 8,
        "block_timestamp": 58773245,
        "timestamp": 58773228,
        "senderPublicKey": "2ac5eef60303003c90f662d89e60570d8661c8ba569e667296f5c7c97a0413ee",
        "senderId": "U8916295525136600565",
        "recipientId": "U2707535059340134112",
        "recipientPublicKey": "5a3c1da429ae925422892e69dc4f0ab6d7ac00cef229d2d992242dcfeca27b91",
        "amount": 0,
        "fee": 100000,
        "signature": "287dc2554025d80...",
        "signatures": [],
        "confirmations": 958117,
        "asset": {
            "chat": {
                "message": "9ae8192972...",
                "own_message": "6802a9e744aa3ba570d7e48fce5fe0f49184d0ce38ea40f7",
                "type": 1
            }
        }
    }
}

Rich Content Messages

Rich Content Message is a special content message transaction that should be processed by client applications. Type of message is 2.

Field message of Rich Content Message should contain encrypted JSON of Rich Text:

{
    type: "RICH_MESSAGE_TYPE",
    text_fallback: "OPTIONAL_FALLBACK_FOR_CLIENTS_NOT_SUPPORTING_THIS_MESSAGE_TYPE"
}

Where type is string value, describing how to handle Rich Text. For example see Crypto Transfer Messages. Optional field text_fallback can be added to show explanation text on client apps that don’t support this type. Rich Text JSON may have any other fields, only type field is required.

For additional information refer to AIP 5: Rich Content Messages.

Example:

{
    "transaction": {
        "type": 8,
        "amount": 0,
        "senderId": "U15677078342684640219",
        "senderPublicKey": "e16e624fd0a5123294b448c21f30a07a0435533c693b146b14e66830e4e20404",
        "asset": {
            "chat": {
                "message": "70cbd07ff2ceaf0fc38a01ef9...",
                "own_message": "e98794eaedf47e...",
                "type": 2
            }
        },
        "recipientId": "U7972131227889954319",
        "timestamp": 46116887,
        "signature": "8fc2a54604109a6fcdccec2..."
    }
}

Crypto Transfer Messages

Crypto Transfer Message is a kind of Rich Content Message designed for displaying In-Chat crypto transfers. Crypto Transfer Message refers to transferring non-ADM transactions. ADM transfers are processed in other ways:

General way of making In-Chat non-ADM transfer:

1 Send Crypto Transfer Message in ADM network 1 Send external token transaction in its own network 1 Watch for external token transaction in its own network and update its status. It is a client app responsibility to validate external token transactions.

Field message of Crypto Transfer Message should contain encrypted JSON including:

  • type — represents token’s network and looks like <coin>_transaction. Examples: eth_transaction, lsk_transaction, dash_transaction, doge_transaction, btc_transaction. Client apps should process type case insensitive, e.g., ETH_transaction = eth_transaction. Mandatory.
  • amount — transferred value in tokens of its network. Decimal separator is .. String, mandatory.
  • comments — optional, and may include comment for this transfer, shown to both recipient and sender.
  • hash — transaction id in token’s network. Used to check transaction status. Mandatory.
  • text_fallback can be added to show explanation text messages on client apps that doesn’t support specified type.

For additional information refer to AIP 12: Non-ADM crypto transfer messages.

Example of message object before encryption:

{
	type: "eth_transaction"
	text_fallback: "Ether transactions are not supported by application yet"
	amount: "0.002"
	comments: "I like to send it, send it"
	hash: "0xfa46d2b3c99878f1f9863fcbdb0bc27d220d7065c6528543cbb83ced84487deb"
}

Signal Messages

Signal Message is a special message transaction that should be hidden by client applications, but processed by services (f. e. registration on Push Notification service). Type of message is 3.

Signal Messages must be encrypted same way as Basic Encrypted Messages.

For additional information refer to AIP 6: Signal Messages.

Sending and fetching messages

To fetch messages from ADAMANT blockchain, use Chats and Chatrooms endpoints.

To send a new message, use /api/chats/process endpoint.