# Extend it with AI (optional)

This page is optional and ungraded. AI output differs from one learner to the next, so the page gives you the requirement and the acceptance checks, not the code. You decide whether the result is done by checking it, not by comparing it with a reference solution.

Use any AI coding assistant that can load the [commercetools AI plugin](/learning-integrate-with-commercetools/dev-tooling/build-with-ai-overview.md). The [`commercetools-connect`](/learning-integrate-with-commercetools/dev-tooling/skills/commercetools-connect.md) skill covers Connect applications, and the [`commercetools-integrations`](/learning-integrate-with-commercetools/dev-tooling/skills/commercetools-integrations.md) skill has a transactional email sub-area for this domain. As in [Use the integration guides](/learning-integrate-with-commercetools/integration-essentials/use-the-integration-guides.md#build-with-ai), ask the assistant which sub-area and step it used.

## The requirement

Zen Electron is launching subscriptions for printer ink. Orders created by a [Recurring Order](/api/projects/recurring-orders.md) schedule emit [`OrderCreatedFromRecurringOrder`](/search.md?urn=ctp:api:type:OrderCreatedFromRecurringOrderMessage) instead of `OrderCreated`. The Connector doesn't subscribe to that type, so customers with a recurring Order get no confirmation.

The [email integration guide](/guides/connect-email-integration.md#map-customer-and-order-messages) names this gap in the template: the type must be added to both the Subscription filter and the handler router. After [Implement and test the event app to the contract](/learning-integrate-with-commercetools/deploy-and-build-connectors/implement-and-test-the-event-app.md), both read one list, so the change should be small. Whether your assistant notices that is part of the exercise.

A starting prompt:

```text
Using the commercetools-connect skill, add the OrderCreatedFromRecurringOrder
Message type to the mail-sender application in this repository, so that it is
handled as an order confirmation. Keep the existing at-most-once acknowledgment
policy and the least-privilege scopes. Add a unit test. Explain each change.
```

## Acceptance checks

The change is done when every check passes:

- **Filter and router.** `ORDER_SUBSCRIPTION_MESSAGE_TYPES`, or whatever the assistant changed instead, makes both the Subscription filter in `src/connector/actions.js` and the router in `src/validators/message.validators.js` include `OrderCreatedFromRecurringOrder`.
- **Unit test.** A test posts an `OrderCreatedFromRecurringOrder` Message to `messageHandler` and asserts that the order confirmation handler runs. Adding the type to the routing test's `it.each` list is enough.
- **Delivery policy unchanged.** The controller still returns `202` as its first statement, so the policy recorded in the README still holds. The [one-sentence test](/learning-integrate-with-commercetools/integration-essentials/price-the-contract.md#the-one-sentence-test) for the contract gives the same three answers as before.
- **Scopes unchanged.** `inheritAs.apiClient.scopes` still lists `manage_subscriptions`, `view_orders`, and `view_customers`, and nothing else.
- **Validation passes.** `npm run test:unit` and `npx eslint src tests` pass, and `commercetools connect validate` reports no findings that your previous release didn't already have. Local SAST can be stricter than the remote gate, so the publishing report for the new tag decides, as described in [Trust the remote report](/learning-integrate-with-commercetools/deploy-and-build-connectors/stage-preview-and-publish-privately.md#trust-the-remote-report).
- **The Subscription has the type after deployment.** Move the Deployment to the new version as on [Operate a Deployment](/learning-integrate-with-commercetools/deploy-and-build-connectors/operate-a-deployment.md#move-to-a-new-version). Don't skip scripts: `postDeploy` must run to update the Subscription. Then [query the Subscription by key](/learning-integrate-with-commercetools/deploy-and-build-connectors/install-and-test-your-connector.md#verify-the-resource-not-the-status) and confirm that `messages` lists the new type.
- **Reviewed against the docs.** You checked each change against the [Connect documentation](/connect/overview.md) and the email guide, not only the assistant's explanation.

If the assistant changed more than this requirement needs, such as adding handlers for other types, reverting the logging changes from [Implement and test the event app to the contract](/learning-integrate-with-commercetools/deploy-and-build-connectors/implement-and-test-the-event-app.md), or adding scopes, reject the change and narrow the prompt.

## Record what you used

Add a line to your repository's README with the following:

- The assistant and model you used.
- The skill and plugin version, as your plugin manager shows it.
- The date.

Skills change between versions, and the same prompt can produce different code. The record tells a reviewer what produced the change.

AI assistance doesn't transfer accountability. You own the code that you merge, and you verify it to the same standard as code you wrote yourself.

## Verify the result, not the report

An assistant's summary of its own work needs the same rule that applies to a Deployment status: verify the resource, not the report. "I added the type to the Subscription" isn't evidence. The Subscription query in the acceptance checks is.

## Key takeaways

- Give an AI assistant a narrow requirement and fixed acceptance checks, and judge the result by the checks.
- A new Message type must reach both the Subscription filter and the router. A shared list makes that one change.
- A change to what `postDeploy` creates needs a redeploy with scripts enabled, and a query of the resource to prove it.
- Record the assistant, model, and skill version that produced a change.
- You remain accountable for AI-generated code. Review it against the documentation, not only against the assistant's explanation.

## Related pages

- [Area overview page with navigation](/learning-integrate-with-commercetools.md)
- [Previous page: Operate a Deployment](/learning-integrate-with-commercetools/deploy-and-build-connectors/operate-a-deployment.md)
- [Next page: Learning check](/learning-integrate-with-commercetools/deploy-and-build-connectors/learning-check.md)
- [Search documentation and API specs](/search.md)