Skip to content

Conversation

@avp1598
Copy link
Contributor

@avp1598 avp1598 commented Jul 9, 2025

No description provided.

/**
* Individual action definition
*/
export type Action = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to XmtpAction. It might be confusing to users with Action from eliza

* Agents use this to present interactive button options to users
*/

export const ActionsContentSchema = z.object({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XmtpActionsContentSchema

Comment on lines +47 to +53
z.object({
id: z.string(),
label: z.string(),
imageUrl: z.string().url().optional(),
style: z.enum(['primary', 'secondary', 'danger']).optional(),
expiresAt: z.string().datetime().optional()
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not create a schema and infer the type on line 22 from it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also use nullish for everything

Comment on lines +112 to +161
if (!content.id || typeof content.id !== 'string') {
throw new Error('Actions.id is required and must be a string')
}

if (!content.description || typeof content.description !== 'string') {
throw new Error('Actions.description is required and must be a string')
}

if (!Array.isArray(content.actions) || content.actions.length === 0) {
throw new Error('Actions.actions is required and must be a non-empty array')
}

if (content.actions.length > 10) {
throw new Error('Actions.actions cannot exceed 10 actions for UX reasons')
}

// Validate each action
content.actions.forEach((action, index) => {
if (!action.id || typeof action.id !== 'string') {
throw new Error(`Action[${index}].id is required and must be a string`)
}

if (!action.label || typeof action.label !== 'string') {
throw new Error(`Action[${index}].label is required and must be a string`)
}

if (action.label.length > 50) {
throw new Error(`Action[${index}].label cannot exceed 50 characters`)
}

if (action.style && !['primary', 'secondary', 'danger'].includes(action.style)) {
throw new Error(`Action[${index}].style must be one of: primary, secondary, danger`)
}

if (action.expiresAt && !this.isValidISO8601(action.expiresAt)) {
throw new Error(`Action[${index}].expiresAt must be a valid ISO-8601 timestamp`)
}
})

// Check for duplicate action IDs
const actionIds = content.actions.map((action) => action.id)
const uniqueActionIds = new Set(actionIds)
if (actionIds.length !== uniqueActionIds.size) {
throw new Error('Action.id values must be unique within Actions.actions array')
}

if (content.expiresAt && !this.isValidISO8601(content.expiresAt)) {
throw new Error('Actions.expiresAt must be a valid ISO-8601 timestamp')
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why aren't we validating with zod?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is their code actually, so i didnt mess with it, its their library sort of, just copy pasted here

* Content Type ID for Intent messages
* Following XIP-67 specification for inline actions
*/
export const ContentTypeIntent = new ContentTypeId({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix with Xmtp

* Intent content structure
* Users express their selection by sending Intent messages when they tap action buttons
*/
export const IntentContentSchema = z.object({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix with Xmtp

/**
* Validates Intent content according to XIP-67 specification
*/
private validateContent(content: IntentContent): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix this entire file with Xmtp

Copy link
Collaborator

@hishboy hishboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please address comments

@hishboy hishboy merged commit b98c674 into main Jul 16, 2025
1 check passed
@hishboy hishboy deleted the avp/quickaction branch July 16, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants