- Task 0: Setup environment
- Task 1: Create a new connection
- Task 2: Send greetings
- Task 3: Prepare for issuing credentials
- Task 4: Issue credential
- Task 5: Verify credential
- Task 6: Issue credential for verified information
- Task 7: Additional tasks
In the previous task, we learned how to establish e2e-encrypted messaging pipes between agents. Now we send our first messages using this communication pipe.
Agents interact using Hyperledger Aries protocols. There are different protocols for different purposes. Agents send text messages to each other using basic message protocol.
In this task:
We will create a new connection according to the steps in task 1. We have already the logic for that in place. In addition, we will add logic to the application to send and receive basic messages:
- Once the connection protocol is complete, the application is notified of the new connection.
- Application sends a greeting to the new connection.
- Application agent initiates the Aries basic message protocol.
- Once the protocol is completed, the application is notified of the message sending success.
- Once the protocol is completed, the wallet user is notified of the received message.
- Wallet user sends a message to the application.
- User agent initiates the Aries basic message protocol.
- Once the protocol is completed, the wallet user is notified of the message sending success (message is displayed in the chat view).
- Once the protocol is completed, the application is notified of the received message.
sequenceDiagram
autonumber
participant Client Application
participant Application Agent
participant User Agent
actor Wallet User
Application Agent->>Client Application: <<New connection!>>
rect rgb(191, 223, 255)
Client Application->>Application Agent: Send greeting
Note right of Application Agent: Aries Basic message protocol
Application Agent->>User Agent: Send message
Application Agent->>Client Application: <<Message sent!>>
User Agent->>Wallet User: <<Message received!>>
end
rect rgb(191, 191, 255)
Wallet User->>User Agent: Send greeting
Note right of Application Agent: Aries Basic message protocol
User Agent->>Application Agent: Send message
User Agent->>Wallet User: <<Message sent!>>
Application Agent->>Client Application: <<Message received!>>
end
In the previous task, we added a handler for new connection notifications. Modify this handler so that when a new connection gets created, we send a greeting to the other agent.
Open file src/listen.ts
.
Add agencyv1
to objects imported from findy-common-ts
:
import { agencyv1, AgentClient, ProtocolClient } from '@findy-network/findy-common-ts'
Modify handler DIDExchangeDone
to following:
// New connection is established
DIDExchangeDone: async (info, didExchange) => {
console.log(`New connection: ${didExchange.getTheirLabel()} with id ${info.connectionId}`)
// Greet each new connection with basic message
const msg = new agencyv1.Protocol.BasicMessageMsg()
msg.setContent('Hi there 👋!')
await protocolClient.sendBasicMessage(info.connectionId, msg)
},
Refresh the /greet
-page and create a new connection using the web wallet UI.
Check that the greeting is received in the web wallet UI.
Continue editing file src/listen.ts
.
Add new handler BasicMessageDone
to listener.
When receiving messages from other agents, print them to log:
DIDExchangeDone: async (info, didExchange) => {
...
},
BasicMessageDone: async (info, basicMessage) => {
// Print out greeting sent from the other agent
if (!basicMessage.getSentByMe()) {
const msg = basicMessage.getContent()
console.log(`Received basic message ${msg} from ${info.connectionId}`)
}
},
Send a reply from the web wallet UI:
Check that the sent message is visible in the server logs:
Congratulations, you have completed task 2, and now know how to send and receive basic messages with the Hyperledger Aries protocol! To revisit what happened, check the sequence diagram.
You can now continue with task 3.