Aller au contenu

« Astreinte » : différence entre les versions

De INDYWiki
Anthony (discussion | contributions)
Anthony (discussion | contributions)
Ligne 241 : Ligne 241 :


===Configuration concrète===
===Configuration concrète===
Il faut choisir un statut autre que "Disponible" qui sera activé pour l'astreinte, "Away" pour cet exemple


On a besoin de gérer deux astreintes. Le poste Accueil reçoit les appels en temps normal
On a besoin de gérer deux astreintes. Le poste Accueil reçoit les appels en temps normal
Ligne 252 : Ligne 250 :
|-
|-
| <syntaxhighlight lang="csharp" line highlight="3-5,8-9">
| <syntaxhighlight lang="csharp" line highlight="3-5,8-9">
public override Task<bool> StartAsync()
    public class SetDynamicAstreinte : ScriptBase<SetDynamicAstreinte>
         {
    {
            string targetExtNum = "100";
         // ============================================================
            string mobileElu = "0699999999";
        // CONFIGURATION — modifier uniquement ces lignes par script
            string profileName = "Away";  
        // ============================================================
 
        private const string TARGET_EXT  = "111";
            // Nommage de l'astreinte
        private const string MOBILE_EXT  = "0612345678";
            string prenomElu = "Marcel";  
        private const string PRENOM_EXT  = "Marcel";
            string nomElu = "Patulacci";  
        private const string NOM_EXT      = "Patulacci";
 
// ============================================================
            try
</syntaxhighlight> || <syntaxhighlight lang="csharp" line highlight="3-5,8-9">
</syntaxhighlight> || <syntaxhighlight lang="csharp" line highlight="3-5,8-9">
public override Task<bool> StartAsync()
    public class SetDynamicAstreinte : ScriptBase<SetDynamicAstreinte>
         {
    {
            string targetExtNum = "100";
        // ============================================================
            string mobileElu = "0688888888";
         // CONFIGURATION — modifier uniquement ces lignes par script
            string profileName = "Away";  
        // ============================================================
 
        private const string TARGET_EXT  = "111";
            // Nommage de l'astreinte
        private const string MOBILE_EXT  = "0699999999";
            string prenomElu = "Jean-Michel";  
        private const string PRENOM_EXT  = "Jean-Michel";
            string nomElu = "Apeuprè";  
        private const string NOM_EXT      = "Apeuprè";
 
// ============================================================
            try
</syntaxhighlight>|| <syntaxhighlight lang="csharp" line highlight="6-8">
</syntaxhighlight>|| <syntaxhighlight lang="csharp" line highlight="3-5,8-9">
    public class ResetAstreinte : ScriptBase<ResetAstreinte>
public override Task<bool> StartAsync()
    {
        {
        // ============================================================
            string targetExtNum = "100";
        // CONFIGURATION — modifier uniquement ces lignes par script
            string mobileElu = "";
        // ============================================================
            string profileName = "Available";  
        private const string TARGET_EXT  = "111";
 
        private const string PRENOM_EXT  = "Accueil";
            // Nommage de l'astreinte
        private const string NOM_EXT      = "Mairie";
            string prenomElu = "Accueil";  
        // ============================================================
            string nomElu = "";  
 
            try
</syntaxhighlight>
</syntaxhighlight>
|}
|}

Version du 28 avril 2026 à 14:59

Principe

On paramètre le statut choisi pour l'astreinte en renvoi vers mon mobile. Un script viendra modifier le statut de l'extension cible ainsi que son numéro de contact mobile, prénom et nom. Ce script déclenchable par l'appel à un code court, paramétrable si on le souhaite sur une BLF.

Paramétrage du statut de l'extension vers mon mobile

  1. Réglages
  2. Transfert d'appels
  3. Choisir le statut de l'extension à activer pour enclencher le renvoi vers l'astreinte. Dans l'exemple Absent. Pas l'état Disponible évidemment.
  4. Dans "Transférer les appels externes à", choisir Mon mobile
  5. Cocher Rebond

Déclaration du script

Rendez-vous dans :

Admin / Intégrations / Scripts d'appels / + Ajouter personnalisé
  1. Donner un nom au traitement de l'appel. Exemple : astreinte_weekend
  2. Créer un code de raccourci, ce qui permettra d'exécuter le script simplement en appelant ce code, et in fine par une BLF. Exemple : *99
  3. OK
  4. Coller dans le champ script le script paramétré ( voir section suivante )
  5. Sauvegarder
  6. Un message doit indiquer Compilation réussie !



Le script d'astreinte

L'éxécution du script va modifier l'extension targetExtNum , il va le basculer sur le statut profileName , modifier son mobile de contact mobileElu , son nom et prénom.

Il faut donc seulement modifier les lignes surlignés dans le code ci-dessous :

using System;
using System.Threading.Tasks;
using TCX.Configuration;
using CallFlow;
using System.Linq;

namespace dummy
{
    public class SetDynamicAstreinte : ScriptBase<SetDynamicAstreinte>
    {
        // ============================================================
        // CONFIGURATION — modifier uniquement ces lignes par script
        // ============================================================
        private const string TARGET_EXT   = "111";
        private const string MOBILE_EXT   = "0612345678";
        private const string PRENOM_EXT   = "Claude";
        private const string NOM_EXT      = "IA";
		 // ============================================================
        
		private const string PROFILE_NAME = "Away";
       
        public override Task<bool> StartAsync()
        {
            try
            {
                IPhoneSystem ps = PhoneSystem.Root;
                Extension ext = ps.GetDNByNumber(TARGET_EXT) as Extension;
                if (ext == null)
                    return Task.FromResult(false);

                // 1. Nom / Prénom
                ext.FirstName = PRENOM_EXT;
                ext.LastName  = NOM_EXT;

                // 2. Numéro mobile
                ext.SetProperty("MOBILENUMBER", MOBILE_EXT);

                // 3. Trouver le profil Away
                FwdProfile targetProfile = ext.FwdProfiles
                    .FirstOrDefault(p => p.Name.Equals(
                        PROFILE_NAME, StringComparison.OrdinalIgnoreCase));

                if (targetProfile != null)
                {
                    // AwayRoute, Internal, External sont read-only
                    // mais ce sont des références : on peut modifier
                    // leurs membres si ceux-ci sont accessibles en écriture
                    AwayRouting route = targetProfile.AwayRoute;

                    // Capturer les HoursDestination comme variables locales
                    // (objets référence — la propriété est read-only,
                    //  mais l'objet pointé est modifiable)
                    HoursDestination internalHours = route.Internal;
                    HoursDestination externalHours = route.External;

                    // Capturer AllHours (struct) → modifier → réassigner
                    DestinationStruct destInternal = internalHours.AllHours;
                    destInternal.To               = DestinationType.Boomerang;
                    destInternal.External         = MOBILE_EXT;
                    internalHours.AllHours        = destInternal;

                    DestinationStruct destExternal = externalHours.AllHours;
                    destExternal.To               = DestinationType.Boomerang;
                    destExternal.External         = MOBILE_EXT;
                    externalHours.AllHours        = destExternal;
                }

                // 4. Sauvegarder
                ext.Save();

                // 5. Recharger et basculer le profil
                ext = ps.GetDNByNumber(TARGET_EXT) as Extension;
                if (ext == null)
                    return Task.FromResult(false);

                FwdProfile profile = ext.FwdProfiles
                    .FirstOrDefault(p => p.Name.Equals(
                        PROFILE_NAME, StringComparison.OrdinalIgnoreCase));

                if (profile != null)
                {
                    ext.CurrentProfile = profile;
                    ext.Save();
                }

                return Task.FromResult(true);
            }
            catch (Exception)
            {
                return Task.FromResult(false);
            }
        }
    }
}

Le script de retour à la normale

using System;
using System.Threading.Tasks;
using TCX.Configuration;
using CallFlow;
using System.Linq;

namespace dummy
{
    public class ResetAstreinte : ScriptBase<ResetAstreinte>
    {
        // ============================================================
        // CONFIGURATION — modifier uniquement ces lignes par script
        // ============================================================
        private const string TARGET_EXT   = "111";
        private const string PRENOM_EXT   = "Accueil";
        private const string NOM_EXT      = "Mairie";
        // ============================================================

        public override Task<bool> StartAsync()
        {
            try
            {
                IPhoneSystem ps = PhoneSystem.Root;
                Extension ext = ps.GetDNByNumber(TARGET_EXT) as Extension;
                if (ext == null)
                    return Task.FromResult(false);

                // 1. Remettre le nom générique
                ext.FirstName = PRENOM_EXT;
                ext.LastName  = NOM_EXT;

                // 2. Vider le numéro mobile
                ext.SetProperty("MOBILENUMBER", "");

                // 3. Résoudre le DN pour la messagerie vocale
                DN targetDN = ps.GetDNByNumber(TARGET_EXT);

                // 4. Remettre AwayRoute → messagerie vocale
                FwdProfile awayProfile = ext.FwdProfiles
                    .FirstOrDefault(p => p.Name.Equals(
                        "Away", StringComparison.OrdinalIgnoreCase));

                if (awayProfile != null)
                {
                    AwayRouting route = awayProfile.AwayRoute;

                    HoursDestination internalHours = route.Internal;
                    HoursDestination externalHours = route.External;

                    DestinationStruct destInternal = internalHours.AllHours;
                    destInternal.To               = DestinationType.VoiceMail;
                    destInternal.Internal         = targetDN;
                    destInternal.External         = "";
                    internalHours.AllHours        = destInternal;

                    DestinationStruct destExternal = externalHours.AllHours;
                    destExternal.To               = DestinationType.VoiceMail;
                    destExternal.Internal         = targetDN;
                    destExternal.External         = "";
                    externalHours.AllHours        = destExternal;
                }

                // 5. Sauvegarder
                ext.Save();

                // 6. Recharger et basculer vers Available
                ext = ps.GetDNByNumber(TARGET_EXT) as Extension;
                if (ext == null)
                    return Task.FromResult(false);

                FwdProfile profile = ext.FwdProfiles
                    .FirstOrDefault(p => p.Name.Equals(
                        "Available", StringComparison.OrdinalIgnoreCase));

                if (profile != null)
                {
                    ext.CurrentProfile = profile;
                    ext.Save();
                }

                return Task.FromResult(true);
            }
            catch (Exception)
            {
                return Task.FromResult(false);
            }
        }
    }
}

Table de correspondance des profileName

Dans 3CX Dans le script
Disponible Available
Absent Away
Ne pas déranger Out of office
Custom 1 Custom 1
Custom 2 Custom 2

Configuration concrète

On a besoin de gérer deux astreintes. Le poste Accueil reçoit les appels en temps normal

Texte de la légende
Marcel Patulacci Jean-Michel Apeuprè Poste accueil hors période d'astreinte
    public class SetDynamicAstreinte : ScriptBase<SetDynamicAstreinte>
    {
        // ============================================================
        // CONFIGURATION — modifier uniquement ces lignes par script
        // ============================================================
        private const string TARGET_EXT   = "111";
        private const string MOBILE_EXT   = "0612345678";
        private const string PRENOM_EXT   = "Marcel";
        private const string NOM_EXT      = "Patulacci";
		 // ============================================================
    public class SetDynamicAstreinte : ScriptBase<SetDynamicAstreinte>
    {
        // ============================================================
        // CONFIGURATION — modifier uniquement ces lignes par script
        // ============================================================
        private const string TARGET_EXT   = "111";
        private const string MOBILE_EXT   = "0699999999";
        private const string PRENOM_EXT   = "Jean-Michel";
        private const string NOM_EXT      = "Apeuprè";
		 // ============================================================
    public class ResetAstreinte : ScriptBase<ResetAstreinte>
    {
        // ============================================================
        // CONFIGURATION — modifier uniquement ces lignes par script
        // ============================================================
        private const string TARGET_EXT   = "111";
        private const string PRENOM_EXT   = "Accueil";
        private const string NOM_EXT      = "Mairie";
        // ============================================================

Une fois les 3 scripts produits, passer à l'étape Déclaration du script qui va permettre d'affecter un code court à chaque script. Exemple :

  • *90 pour hors période d'astreinte
  • *91 pour Jean-Michel
  • *92 pour Marcel

On peut communiquer les codes aux personnes habilitées à gérer le système d'astreinte et aller jusqu'à paramétrer des BLF pour faciliter la vie d'une secrétaire par exemple.

Valide v20