GetMessage
Usage
Import the Any declaration to interact with the GetMessage function to retrieve the specific message of your choice.
Then call the GetMessage function, with the required parameters as follow:
Parameters
Parameter | Description |
---|---|
hash - required string | The hash of your message. |
channel - optional string | Channel of the message. |
messageType - optional MessageType | The type of message you are waiting for: post, aggregate, forget, store, program. |
APIServer - optional string | The APIServer to use to resolve the request. The default one is: https://api2.aleph.im |
Result
When you are fetching a message with GetMessage, there are 3 ending scenarios:
A. Keep default
By default, the GetMessage method will return a BaseMessage object. This will allow you to get with auto-completion generic information about the message like the sender, date, chain, ... that does not depend on its type (Post, Store, Aggregate, ...).
B. Use templating
The GetMessage allows you to override its default templating return type. This means if you know the type of message you are looking for, you can add your type to it like this:
This method is perfom an override of the type without further verification. This can lead as unexptected runtime errors if the given type is not the same as the type fetched by the Aleph API.
C. Use Typeguards
This is the safest way to handle messages retrieved by GetMessage or GetMessages. You can find more informaton about them on their dedicated page.
Errors handling
In case the provided hash does not refer to any message stored on the Aleph network, GetMessage will throw an error as the following:
No messages found for: <The Hash you provide>
Last updated