Inquiry About ~*req. Function in CGRateS

137 views
Skip to first unread message

selim jabou

unread,
Feb 25, 2025, 1:09:46 PMFeb 25
to CGRateS
I would like to sincerely thank you for your efforts in developing and maintaining CGRateS. Your work is highly appreciated!

I am new to using CGRateS and have been exploring different functionalities, particularly the ~*req. function used in AttributeS and FilterS. Through testing, I have successfully used it in cases like ~*req.RequestType and ~*req.Account. However, I would like to better understand its full capabilities. My main question is:

What variables can be accessed using ~*req.?
Where does ~*req. retrieve values from?

Is there a reference or documentation that lists all possible request parameters?
I would really appreciate any guidance on this topic. Thank you in advance for your help!

Armir Veliaj

unread,
Feb 27, 2025, 11:12:08 AMFeb 27
to CGRateS
Hi Selim,

For a better understanding of *req usage, you can check it via ngrep while an event is being sent. In ngrep, the request will contain an event and APIopts in it,*req represents the event, with each field of the event being usable in *req, while *opts refers to the APIopts in the request.

If you want to dive deeper into how filters work on an event, you can refer to our documentation on filters: https://cgrates.readthedocs.io/en/latest/filters.html#filters . Additionally, you can check this CSV file example: https://github.com/cgrates/cgrates/blob/master/data/tariffplans/oldtutorial/Filters.csv, where req. has different parameters.

Thanks,
Armir

selim jabou

unread,
Feb 28, 2025, 12:26:35 PMFeb 28
to CGRateS

Thank you for your previous responses and the examples provided. I truly appreciate your help.

I was initially trying to use the *req functions to modify the RatingSubject dynamically in the Attributes field, specifically using : ~*req.RatingSubject

However, it didn’t seem to work for me. I also wasn’t sure if I was correctly referencing the SubjectType using this function, as I encountered no errors when executing it. That being said, we have now changed our approach and no longer need to modify the RatingSubject dynamically.

That brings me to another question:

I have successfully set up an alert email when an account’s balance reaches a specific amount using Actions and ActionTriggers, and it works perfectly. However, I couldn’t find where I could customize the content of the email.  I would like to modify the content of this email to make it more user-friendly. Could you please point me to the correct configuration for customizing the email body?  Below is an example of the email I receive:

Time:
        2025-02-28 16:57:53.020435464 +0000 UTC m=+128.286214015

Balance:
        {"ID":"DIGIVOIP:selim2","BalanceMap":{"*monetary":[{"Uuid":"1e4a8a29-c163-4dc1-9213-af5630726fd7","ID":"REFILL_10","Value":-32,"ExpirationDate":"0001-01-01T00:00:00Z","Weight":10,"DestinationIDs":null,"RatingSubject":"","Categories":null,"SharedGroups":null,"Timings":null,"TimingIDs":null,"Disabled":false,"Factors":null,"Blocker":false}]},"UnitCounters":null,"ActionTriggers":[{"ID":"ActionTrigger_Mail","UniqueID":"8c27f5b6-6b6e-439f-b14f-8d40aadb74bb","ThresholdType":"*min_balance","ThresholdValue":8,"Recurrent":true,"MinSleep":0,"ExpirationDate":"0001-01-01T00:00:00Z","ActivationDate":"0001-01-01T00:00:00Z","Balance":{"Uuid":null,"ID":null,"Type":"*monetary","Value":null,"ExpirationDate":null,"Weight":null,"DestinationIDs":null,"RatingSubject":null,"Categories":null,"SharedGroups":null,"TimingIDs":null,"Timings":null,"Disabled":null,"Factors":null,"Blocker":null},"Weight":0,"ActionsID":"Action_Mail_Alert","MinQueuedItems":0,"Executed":true,"LastExecutionTime":"2025-02-28T16:57:53.0
 20372446Z"}],"AllowNegative":false,"Disabled":false,"UpdateTime":"2025-02-28T16:55:53.02696396Z"}

Yours faithfully,
CGR Balance Monitor



here is my Action and ActionTrigger : 


{
    "method": "APIerSv1.SetActions",
    "params": [
        {
          "ActionsId": "Action_Mail_Alert",
          "Actions": [
              {
                  "Identifier": "*cdrlog",
                  "BalanceId": "",
                  "BalanceUuid": "",
                  "BalanceType": "*monetary",
                  "Directions": "*out",
                  "Units": 0,
                  "ExpiryTime": "",
                  "Filter": "",
                  "TimingTags": "",
                  "DestinationIds": "",
                  "RatingSubject": "",
                  "Categories": "",
                  "SharedGroups": "",
                  "BalanceWeight": 0,
                  "ExtraParameters": "{\"Category\":\"^activation\",\"Destination\":\"Balance dipped below $8\"}",
                  "BalanceBlocker": "false",
                  "BalanceDisabled": "false",
                  "Weight": 80
              },
              {
                  "Identifier": "*mail_async",
                  "ExtraParameters": "reci...@mail.com",
                  "ExpiryTime": "*unlimited",
                  "Weight": 700
              },
              {
                  "Identifier": "*log",
                  "Weight": 1200
              }
          ]
        }
    ]
}



{
    "method": "APIerSv1.SetActionTrigger",
    "params": [
        {
            "GroupID" : "ActionTrigger_Mail",
            "ActionTrigger":
                {
                    "BalanceType": "*monetary",
                    "Balance" : {
                        "BalanceType": "*monetary",
                        "ID" : "*default",
                        "BalanceID" : "*default",
                        "Value" : 8
                        },
                    "ThresholdType": "*min_balance",
                    "Recurrent": true,
                    "ThresholdValue": 8,
                    "Weight": 10,
                    "ActionsID" : "Action_Mail_Alert"
                },
            "Overwrite": true
        }
    ]
}

Armir Veliaj

unread,
Mar 4, 2025, 5:17:26 AMMar 4
to CGRateS
Hi Selim,

The mail action was more for PoC and it's not intended for production use. We suggest it would be better to use an HTTP solution for this and integrate your mailer behind it by using *http_post to send extra data.

Thanks,
Armir

selim jabou

unread,
Mar 5, 2025, 8:27:03 AMMar 5
to CGRateS
ah okay, thank you for your time.

Selim
Reply all
Reply to author
Forward
0 new messages