|
| 1 | +import type { ActionDefinition } from "../../core/types.ts"; |
| 2 | + |
| 3 | +import { s } from "../../core/json-schema.ts"; |
| 4 | +import { defineProviderAction } from "../../core/provider-definition.ts"; |
| 5 | + |
| 6 | +const service = "altiria"; |
| 7 | + |
| 8 | +const customFieldSchema = s.object( |
| 9 | + "One Altiria contact custom field value.", |
| 10 | + { |
| 11 | + key: s.nonEmptyString("Custom field name."), |
| 12 | + type: s.stringEnum("Custom field type.", ["string", "date", "decimal"]), |
| 13 | + value: s.nonEmptyString("Custom field value."), |
| 14 | + }, |
| 15 | + { optional: ["type"] }, |
| 16 | +); |
| 17 | + |
| 18 | +const includeSchema = s.array( |
| 19 | + "Associated contact resources to include in the response.", |
| 20 | + s.stringEnum("One associated contact resource name.", ["customFields", "groups"]), |
| 21 | + { minItems: 1 }, |
| 22 | +); |
| 23 | + |
| 24 | +const metadataSchema = s.looseObject("Pagination and other metadata returned by Altiria."); |
| 25 | + |
| 26 | +const smsSchema = s.looseObject("One normalized Altiria SMS message.", { |
| 27 | + id: s.nullable(s.string("Altiria SMS message identifier.")), |
| 28 | + from: s.nullable(s.string("Sender value used for the SMS message.")), |
| 29 | + to: s.nullable(s.string("Recipient phone number.")), |
| 30 | + message: s.nullable(s.string("SMS message body.")), |
| 31 | + campaignId: s.nullable(s.integer("Altiria campaign identifier.")), |
| 32 | + sendingId: s.nullable(s.integer("Altiria sending identifier.")), |
| 33 | + isDelivered: s.nullable(s.boolean("Whether Altiria reports the message as delivered.")), |
| 34 | + isClicked: s.nullable(s.boolean("Whether Altiria reports a shortened link click.")), |
| 35 | + raw: s.looseObject("Raw Altiria SMS object."), |
| 36 | +}); |
| 37 | + |
| 38 | +const sendSmsOutputSchema = s.requiredObject("The result returned by Altiria after sending SMS.", { |
| 39 | + accepted: s.boolean("Whether Altiria accepted the SMS request."), |
| 40 | + messages: s.array("SMS message records returned by Altiria.", smsSchema), |
| 41 | + raw: s.unknown("Raw Altiria response payload."), |
| 42 | +}); |
| 43 | + |
| 44 | +const contactSchema = s.looseObject("One normalized Altiria contact.", { |
| 45 | + id: s.nullable(s.integer("Altiria contact identifier.")), |
| 46 | + email: s.nullable(s.string("Contact email address.")), |
| 47 | + phone: s.nullable(s.string("Contact mobile phone number.")), |
| 48 | + landline: s.nullable(s.string("Contact landline phone number.")), |
| 49 | + countryIso: s.nullable(s.string("Two-letter contact country code.")), |
| 50 | + name: s.nullable(s.string("Contact first name.")), |
| 51 | + surname: s.nullable(s.string("Contact surname.")), |
| 52 | + createdAt: s.nullable(s.string("Contact creation timestamp returned by Altiria.")), |
| 53 | + updatedAt: s.nullable(s.string("Contact update timestamp returned by Altiria.")), |
| 54 | + raw: s.looseObject("Raw Altiria contact object."), |
| 55 | +}); |
| 56 | + |
| 57 | +const groupSchema = s.looseObject("One normalized Altiria contact group.", { |
| 58 | + id: s.nullable(s.integer("Altiria group identifier.")), |
| 59 | + name: s.nullable(s.string("Altiria group name.")), |
| 60 | + raw: s.looseObject("Raw Altiria group object."), |
| 61 | +}); |
| 62 | + |
| 63 | +const contactWriteFields = { |
| 64 | + email: s.email("Contact email address."), |
| 65 | + phone: s.nonEmptyString("Contact mobile phone number with international prefix."), |
| 66 | + landline: s.nonEmptyString("Contact landline phone number."), |
| 67 | + countryIso: s.string("Two-letter country code required when phone or landline is specified.", { |
| 68 | + minLength: 2, |
| 69 | + maxLength: 2, |
| 70 | + }), |
| 71 | + groupsIds: s.array("Contact group IDs to attach this contact to.", s.integer("One Altiria group ID."), { |
| 72 | + minItems: 1, |
| 73 | + }), |
| 74 | + groupsNames: s.array("Contact group names to attach this contact to.", s.nonEmptyString("One Altiria group name."), { |
| 75 | + minItems: 1, |
| 76 | + }), |
| 77 | + name: s.nonEmptyString("Contact first name."), |
| 78 | + surname: s.nonEmptyString("Contact surname."), |
| 79 | + customFields: s.array("Custom fields to set on this contact.", customFieldSchema, { |
| 80 | + minItems: 1, |
| 81 | + }), |
| 82 | +}; |
| 83 | + |
| 84 | +const contactWriteOptionalKeys: readonly (keyof typeof contactWriteFields & string)[] = [ |
| 85 | + "email", |
| 86 | + "phone", |
| 87 | + "landline", |
| 88 | + "countryIso", |
| 89 | + "groupsIds", |
| 90 | + "groupsNames", |
| 91 | + "name", |
| 92 | + "surname", |
| 93 | + "customFields", |
| 94 | +]; |
| 95 | + |
| 96 | +const sendSms = defineProviderAction(service, { |
| 97 | + name: "send_sms", |
| 98 | + description: "Send an SMS message through Altiria's REST SMS endpoint.", |
| 99 | + inputSchema: s.object( |
| 100 | + "The input payload for sending an Altiria SMS message.", |
| 101 | + { |
| 102 | + to: s.array( |
| 103 | + "Recipient mobile phone numbers with international prefix.", |
| 104 | + s.nonEmptyString("One recipient mobile phone number."), |
| 105 | + { minItems: 1 }, |
| 106 | + ), |
| 107 | + from: s.nonEmptyString("SMS sender value registered or allowed in Altiria."), |
| 108 | + message: s.nonEmptyString("SMS body text to send."), |
| 109 | + notificationUrl: s.anyOf("Delivery notification URL, either shared by all recipients or one URL per recipient.", [ |
| 110 | + s.url("One delivery notification URL."), |
| 111 | + s.array("Delivery notification URLs by recipient.", s.url("One delivery URL."), { |
| 112 | + minItems: 1, |
| 113 | + }), |
| 114 | + ]), |
| 115 | + campaignName: s.nonEmptyString("Optional campaign name used in Altiria statistics."), |
| 116 | + tags: s.array("Campaign tags to attach to the send.", s.nonEmptyString("One tag."), { |
| 117 | + minItems: 1, |
| 118 | + }), |
| 119 | + certified: s.boolean("Whether to send the message as certified SMS."), |
| 120 | + splitParts: s.boolean("Whether Altiria should split long SMS messages into SMS parts."), |
| 121 | + flash: s.boolean("Whether to send the message as a Flash SMS."), |
| 122 | + sub: s.array( |
| 123 | + "Substitution variable objects, one per recipient.", |
| 124 | + s.record("Substitution variables for one recipient.", s.unknown("Variable value.")), |
| 125 | + { minItems: 1 }, |
| 126 | + ), |
| 127 | + }, |
| 128 | + { |
| 129 | + optional: ["notificationUrl", "campaignName", "tags", "certified", "splitParts", "flash", "sub"], |
| 130 | + }, |
| 131 | + ), |
| 132 | + outputSchema: sendSmsOutputSchema, |
| 133 | +}); |
| 134 | + |
| 135 | +const getSms = defineProviderAction(service, { |
| 136 | + name: "get_sms", |
| 137 | + description: "Fetch SMS information from Altiria by one or more message identifiers.", |
| 138 | + inputSchema: s.requiredObject("The input payload for fetching Altiria SMS information.", { |
| 139 | + id: s.nonEmptyString("Altiria SMS message identifier, or multiple identifiers separated by commas."), |
| 140 | + }), |
| 141 | + outputSchema: s.requiredObject("SMS messages returned by Altiria.", { |
| 142 | + messages: s.array("SMS message records returned by Altiria.", smsSchema), |
| 143 | + raw: s.unknown("Raw Altiria response payload."), |
| 144 | + }), |
| 145 | +}); |
| 146 | + |
| 147 | +const listContacts = defineProviderAction(service, { |
| 148 | + name: "list_contacts", |
| 149 | + description: "List contacts from the connected Altiria account.", |
| 150 | + inputSchema: s.object( |
| 151 | + "The input payload for listing Altiria contacts.", |
| 152 | + { |
| 153 | + limit: s.integer("Maximum contacts to return in one request.", { minimum: 1, maximum: 1000 }), |
| 154 | + page: s.integer("Result page to request.", { minimum: 1 }), |
| 155 | + include: includeSchema, |
| 156 | + }, |
| 157 | + { optional: ["limit", "page", "include"] }, |
| 158 | + ), |
| 159 | + outputSchema: s.requiredObject("Contacts returned by Altiria.", { |
| 160 | + contacts: s.array("Contact records returned by Altiria.", contactSchema), |
| 161 | + meta: s.nullable(metadataSchema), |
| 162 | + raw: s.unknown("Raw Altiria response payload."), |
| 163 | + }), |
| 164 | +}); |
| 165 | + |
| 166 | +const getContact = defineProviderAction(service, { |
| 167 | + name: "get_contact", |
| 168 | + description: "Fetch one Altiria contact by contact ID.", |
| 169 | + inputSchema: s.object( |
| 170 | + "The input payload for fetching one Altiria contact.", |
| 171 | + { |
| 172 | + id: s.integer("Altiria contact identifier."), |
| 173 | + include: includeSchema, |
| 174 | + }, |
| 175 | + { optional: ["include"] }, |
| 176 | + ), |
| 177 | + outputSchema: s.requiredObject("Contact returned by Altiria.", { |
| 178 | + contact: contactSchema, |
| 179 | + raw: s.unknown("Raw Altiria response payload."), |
| 180 | + }), |
| 181 | +}); |
| 182 | + |
| 183 | +const createContact = defineProviderAction(service, { |
| 184 | + name: "create_contact", |
| 185 | + description: "Create a new Altiria contact.", |
| 186 | + inputSchema: s.object("The input payload for creating an Altiria contact.", contactWriteFields, { |
| 187 | + optional: contactWriteOptionalKeys, |
| 188 | + }), |
| 189 | + outputSchema: s.requiredObject("Contact created by Altiria.", { |
| 190 | + contact: contactSchema, |
| 191 | + raw: s.unknown("Raw Altiria response payload."), |
| 192 | + }), |
| 193 | +}); |
| 194 | + |
| 195 | +const updateContact = defineProviderAction(service, { |
| 196 | + name: "update_contact", |
| 197 | + description: "Update an existing Altiria contact.", |
| 198 | + inputSchema: s.object( |
| 199 | + "The input payload for updating an Altiria contact.", |
| 200 | + { |
| 201 | + id: s.integer("Altiria contact identifier."), |
| 202 | + ...contactWriteFields, |
| 203 | + }, |
| 204 | + { optional: contactWriteOptionalKeys }, |
| 205 | + ), |
| 206 | + outputSchema: s.requiredObject("Contact updated by Altiria.", { |
| 207 | + contact: contactSchema, |
| 208 | + raw: s.unknown("Raw Altiria response payload."), |
| 209 | + }), |
| 210 | +}); |
| 211 | + |
| 212 | +const deleteContact = defineProviderAction(service, { |
| 213 | + name: "delete_contact", |
| 214 | + description: "Delete one Altiria contact by contact ID.", |
| 215 | + inputSchema: s.requiredObject("The input payload for deleting one Altiria contact.", { |
| 216 | + id: s.integer("Altiria contact identifier."), |
| 217 | + }), |
| 218 | + outputSchema: s.requiredObject("Delete status returned after removing an Altiria contact.", { |
| 219 | + deleted: s.boolean("Whether the contact delete request succeeded."), |
| 220 | + }), |
| 221 | +}); |
| 222 | + |
| 223 | +const listGroups = defineProviderAction(service, { |
| 224 | + name: "list_groups", |
| 225 | + description: "List contact groups from the connected Altiria account.", |
| 226 | + inputSchema: s.object( |
| 227 | + "The input payload for listing Altiria contact groups.", |
| 228 | + { |
| 229 | + limit: s.integer("Maximum groups to return in one request.", { minimum: 1, maximum: 1000 }), |
| 230 | + page: s.integer("Result page to request.", { minimum: 1 }), |
| 231 | + }, |
| 232 | + { optional: ["limit", "page"] }, |
| 233 | + ), |
| 234 | + outputSchema: s.requiredObject("Contact groups returned by Altiria.", { |
| 235 | + groups: s.array("Group records returned by Altiria.", groupSchema), |
| 236 | + meta: s.nullable(metadataSchema), |
| 237 | + raw: s.unknown("Raw Altiria response payload."), |
| 238 | + }), |
| 239 | +}); |
| 240 | + |
| 241 | +export const altiriaActions: ActionDefinition[] = [ |
| 242 | + sendSms, |
| 243 | + getSms, |
| 244 | + listContacts, |
| 245 | + getContact, |
| 246 | + createContact, |
| 247 | + updateContact, |
| 248 | + deleteContact, |
| 249 | + listGroups, |
| 250 | +]; |
0 commit comments