There are cases when one party needs to receive an answer to a specific question from another party. For instance, it can be to authorize transactions, validate logins (2FA), accept terms and conditions, and other cases.
There are two roles in the question answering process: Questioner and Responder.
- The Questioner is the party that asks a question with its valid answers. Verity SDK can be used as an Questioner.
- The Responder is the party that responds with the selected answer. Mobile SDK represents the responds party. Bellow in this document we will explain which steps need to be taken in order to respond on the question on the Responder side using Mobile SDK.
NOTE: library should be initialized before using questions API. See initialization documentation
NOTE: there must be established connection between Sender and Received. See connections document
To complete this section read through the following sections:
- Download and Parse Question message received from the Pairwise Cloud Agent.
- Update message (connected to Question) status on the Agent as reviewed
- Answer on received Question
- Select answer
- Deserialize associated Connection
- Send answer message
On of the possible formats may match the following structure:
{
"pwDid" - string, // reference to the connection from which proof request was received
"entryId" - string, // identifier of question protocol.
// metadata to show on the UI
"answers": List<json>, // list of available answers
"selectedAnswer": json, // selected answer
// optionally
"connectionName": string // name of the connection from which Crdential Offer was received
"connectionLogo": string // logo of the connection from which Crdential Offer was received
"timestamp": int // optional, time of answering (it can be shown on the UI)
"status" - string, // proof status (received / answered)
}
Later in this document, we will show how to get each of these fields.
-
Download pending messages See messages documentation for messages downloading information. Pending messages with
question
orcommitted-question
type should be used.{ "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/committedanswer/1.0/question", "@id": "5b4c8a32-ceae-48e1-bd6b-ffa2a07ddbf0", "question_text": "Hi, Thomas", "question_detail": "Are you on the phone with the credit union right now about transferring $100.00?", "valid_responses": [ { "text": "Yes, I am", "nonce": "255c41413dcffcfaa4fe909cd65e477a5ed77d1550ba7f2c52cac58af84c4b8d" }, { "text": "No, I am not", "nonce": "2a2a22bc64ecfda55fa40a2c9227c3592ac1399e63688b58d5f33c64b4326f77" } ], "@timing": { "expires_time": "2018-12-13T17:29:06+0000" } }
The following fields can be used to show the question on the UI:
question_text
- Question to show to userquestion_details
- Additional details for questionvalid_responses
- Array of possible answers for question. Each entry has following fields:text
- Readable representation of valid response.
- Update status of correspondent message on the Agent as reviewed. See messages documentation for message update information.
-
Select response option to be used
answerJson = JSON.toString({ "text": "Yes, I am", "nonce": "255c41413dcffcfaa4fe909cd65e477a5ed77d1550ba7f2c52cac58af84c4b8d" })
-
Deserialize Connection state object associated with received Question message
[appDelegate.sdkApi connectionDeserialize:serializedConnection completion:^(NSError *error, NSInteger connectionHandle) { // ... }];
int connectionHandle = ConnectionApi.connectionDeserialize(serializedConnection).get();
-
Send answer message
[appDelegate.sdkApi connectionSendAnswer:connHandle question:questionJson answer:answerJson withCompletion:^(NSError *error) { // ... }];
ConnectionApi.connectionSendAnswer(connHandle, questionJson, answerJson).get();
Now your application is able to answer questions. Congratulations your application now supports base functionality! You are ready to read how to handle connection invitations containing attached messages.