There are two ways to do this:
(1) API
You can do this by subscribing to presence events for the two phone numbers which will send events to your apps that you can then use to call the Desk.com API to create a ticket.
You can either use the Subscription API or Webhooks:
Subscription API:
https://github.com/ringcentral/ringcentral-api-docs/blob/master/docs/notifications.mdWebhooks:
https://github.com/ringcentral/ringcentral-api-docs/blob/master/docs/webhooks.mdUsing these you can subscribe for the extension presence eventFilter. When you receive events you can use that information to create a case in Desk.com or optionally make another request to RingCentral for more info before creating the case.
(2) Zapier
You can also use Zapier to create a new Desk.com case whenever a RingCentral call ends. To do this, you can use the "Call Ended" trigger with the Desk.com with the "Create Case" action.