Skip to content

Commit

Permalink
feat: update index
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharking committed Dec 12, 2024
1 parent 4dcf175 commit a0363f2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/chatbot/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const rootMenuAsQA = {
{ id: 'poll', text: '⚽ World Cup poll' },
{ id: 'rocky', text: '💪 Rocky quotes' },
{ id: 'issue', text: 'Issue credential' },
{ id: 'revoke', text: 'Revoke credential' },
{ id: 'proof', text: 'Request proof' },
{ id: 'help', text: '🆘 Help' },
],
Expand Down
47 changes: 45 additions & 2 deletions examples/chatbot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ app.set('json spaces', 2)
const expressHandler = new ExpressEventHandler(app)

let phoneNumberCredentialDefinitionId: string | undefined
let phoneNumberRevocationDefinitionId: string | undefined
let phoneNumberRevocationCount: number = 0

type OngoingCall = {
wsUrl: string
Expand All @@ -83,9 +85,19 @@ const server = app.listen(PORT, async () => {
)

try {
const credentialDefinition = (await apiClient.credentialTypes.create({
id: randomUUID(),
name: "phoneNumber",
version: '1.0',
attributes: ['phoneNumber']
}))
// const credentialDefinition = (await apiClient.credentialTypes.import(phoneCredDefData))
phoneNumberCredentialDefinitionId =
phoneNumberCredentialType?.id ?? (await apiClient.credentialTypes.import(phoneCredDefData)).id
phoneNumberCredentialType?.id ?? credentialDefinition.id
phoneNumberRevocationDefinitionId =
phoneNumberCredentialType?.revocationId ?? credentialDefinition.revocationId
logger.info(`phoneNumberCredentialDefinitionId: ${phoneNumberCredentialDefinitionId}`)
logger.info(`phoneNumberCredentialDefinitionId: ${phoneNumberRevocationDefinitionId}`)
} catch (error) {
logger.error(`Could not create or retrieve phone number credential type: ${error}`)
}
Expand Down Expand Up @@ -154,7 +166,33 @@ const handleMenuSelection = async (options: { connectionId: string; item: string

// Issue credential
if (selectedItem === 'issue' || selectedItem === 'Issue credential') {
if (!phoneNumberCredentialDefinitionId || phoneNumberCredentialDefinitionId === '') {
if (!phoneNumberCredentialDefinitionId || phoneNumberCredentialDefinitionId === '' ||
!phoneNumberRevocationDefinitionId || phoneNumberRevocationDefinitionId === '') {
await sendTextMessage({
connectionId,
content: 'Service not available',
})
} else {
const body = new CredentialIssuanceMessage({
connectionId,
credentialDefinitionId: phoneNumberCredentialDefinitionId,
claims: [
{
name: 'phoneNumber',
mimeType: 'text/plain',
value: '+5712345678',
},
],
revocationDefinitionId: phoneNumberRevocationDefinitionId,
revocationRegistryIndex: phoneNumberRevocationCount += 1,
})
await apiClient.messages.send(body)
}
}

if (selectedItem === 'revoke' || selectedItem === 'Revoke credential') {
if (!phoneNumberCredentialDefinitionId || phoneNumberCredentialDefinitionId === '' ||
!phoneNumberRevocationDefinitionId || phoneNumberRevocationDefinitionId === '') {
await sendTextMessage({
connectionId,
content: 'Service not available',
Expand All @@ -170,6 +208,8 @@ const handleMenuSelection = async (options: { connectionId: string; item: string
value: '+5712345678',
},
],
revocationDefinitionId: phoneNumberRevocationDefinitionId,
revocationRegistryIndex: phoneNumberRevocationCount,
})
await apiClient.messages.send(body)
}
Expand Down Expand Up @@ -383,6 +423,9 @@ expressHandler.messageReceived(async (req, res) => {
const body = new CallOfferRequestMessage({
connectionId: obj.connectionId,
description: 'Start call',
offerExpirationTime: new Date(
Date.now() + 60 * 1000,
),
parameters: { wsUrl, roomId, peerId },
})
await apiClient.messages.send(body)
Expand Down

0 comments on commit a0363f2

Please sign in to comment.