<@U04UQ68083H> when edit profile, how to detect ev...
# ory-copilot
n
@chilly-king-10285 when edit profile, how to detect event i only want to send webhook when I only edit phone number
b
A message from kapa.ai
To detect when only the phone number is edited in a user's profile and send a webhook specifically for that event, you can use Ory Actions with a webhook configured for the settings flow. Here's how you can approach this: 1. Set up a webhook for the settings flow: Configure a webhook action for the "after" settings flow in your Ory Identities configuration. 2. Use Jsonnet templating to check for phone number changes: In the webhook configuration, use Jsonnet templating to compare the old and new phone number values. If they differ, you can trigger the webhook. Here's an example of how you might structure your Jsonnet template for the webhook:
Copy code
jsonnet function(ctx)   if ctx.flow.type == "settings" && ctx.identity.traits.phone != ctx.flow.request_body.traits.phone then     {       event: "phone_number_changed",       old_phone: ctx.identity.traits.phone,       new_phone: ctx.flow.request_body.traits.phone     }   else     error "cancel"
This template does the following: - Checks if the flow type is "settings" - Compares the phone number in the current identity traits with the phone number in the request body - If they're different, it returns an object with the event details - If they're the same (or if it's not a settings flow), it cancels the webhook 3. Configure the webhook: Set up your webhook in the Ory Console or configuration file, using the Jsonnet template above in the
body
field of the webhook config. For more detailed information on configuring webhooks and using Jsonnet templating, you can refer to the [Ory documentation on webhooks](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks). Remember that this approach assumes that the phone number is stored in the
traits.phone
field of the identity. Adjust the field names if your schema is different. Also, note that this method will only trigger the webhook when the phone number is changed, regardless of whether other fields are also changed in the same settings update. If you need more complex logic, you might need to adjust the Jsonnet template accordingly.