<?xml version="1.0" encoding="utf-8"?>
<Crm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Country="CH" Name="Couverty" Version="2" SupportsEmojis="false" SupportsTranscription="false">
  <Number Prefix="Plus" MaxLength="15" />
  <Connection MaxConcurrentRequests="2" />
  <Parameters>
    <Parameter Name="ApiUrl" Type="String" Parent="General Configuration" Editor="String" Title="URL de l'API Couverty:" Validation="" Default="https://app.couverty.ch" ListValues="" RequestUrl="" RequestUrlParameters="" ResponseScenario="" />
    <Parameter Name="ApiKey" Type="String" Parent="General Configuration" Editor="String" Title="Clé API (format qr_xxx):" Validation="" Default="" ListValues="" RequestUrl="" RequestUrlParameters="" ResponseScenario="" />
    <Parameter Name="ReportCallEnabled" Type="Boolean" Parent="" Editor="String" Title="Activer le journal des appels" Validation="" Default="True" ListValues="" RequestUrl="" RequestUrlParameters="" ResponseScenario="" />
  </Parameters>
  <Authentication Type="No" />
  <Scenarios>
    <!-- Lookup automatique: déclenché par 3CX lors d'un appel entrant/sortant -->
    <Scenario Id="" Type="REST" EntityId="Contacts" EntityOrder="">
      <Request SkipIf="" Url="[ApiUrl]/api/integrations/3cx/lookup?phone=[Number]&amp;apikey=[ApiKey]" MessagePasses="0" Message="" RequestContentType="" RequestEncoding="UrlEncoded" RequestType="Get" ResponseType="Json" />
      <Rules>
        <Rule Type="Any" Ethalon="">id</Rule>
      </Rules>
      <Variables>
        <Variable Name="ContactId" LookupValue="" Path="">id<Filter /></Variable>
        <Variable Name="FirstName" LookupValue="" Path="">firstName<Filter /></Variable>
        <Variable Name="LastName" LookupValue="" Path="">lastName<Filter /></Variable>
        <Variable Name="PhoneBusiness" LookupValue="" Path="">phone<Filter /></Variable>
      </Variables>
      <Outputs AllowEmpty="false">
        <Output Type="FirstName" Passes="0" Value="[FirstName]" />
        <Output Type="LastName" Passes="0" Value="[LastName]" />
        <Output Type="PhoneBusiness" Passes="0" Value="[PhoneBusiness]" />
        <Output Type="EntityId" Passes="0" Value="[ContactId]" />
        <Output Type="EntityType" Passes="0" Value="Contact" />
      </Outputs>
    </Scenario>
    <!-- ReportCall: déclenché par 3CX à la fin de chaque appel -->
    <Scenario Id="ReportCall" Type="REST" EntityId="" EntityOrder="">
      <Request SkipIf="[ReportCallEnabled]!=True" Url="[ApiUrl]/api/integrations/3cx/report-call?apikey=[ApiKey]" MessagePasses="0" Message="" RequestContentType="application/json" RequestEncoding="Json" RequestType="Post" ResponseType="Json" />
      <Variables />
      <Outputs AllowEmpty="false" />
      <RequestBody><![CDATA[{
  "phoneNumber": "[Number]",
  "callType": "[CallType]",
  "agent": "[Agent]",
  "callDateTime": "[[CallStartTimeUTC].ToString(yyyy-MM-ddTHH:mm:ssZ)]"
}]]></RequestBody>
    </Scenario>
  </Scenarios>
</Crm>
