USSD Callback Service FTL Example

Unstructured Supplementary Service Data (USSD) callback service notifications for different callback request results are configured in the /opt/mtx/notifier/templates/ussd/ussd-query/mtxUssdQueryNotification.ftl file.

Example Configuration

The following example Apache FreeMarker template configuration includes configuration to handle notifications for USSD callback services in addition to configuration to handle notifications for USSD query services.

In this example configuration, the following lines set the FTL header parameter values:
<#setting output_encoding="UTF-8">
<#-- Header values that can be set:
<#t>${request.setHeader('sendAsNotify', false)}
<#t>${request.setHeader('globalTitleType', 4)}
<#t>${request.setHeader('globalTitleContent', '55556')}
<#t>${request.setHeader('dataEncodingScheme', 1)} -->
<#-- Language is ${headers.language} -->
The following lines configure USSD query notification messages for the USSD query service code 121:
body.result for UssdCallBack can be one of       
              UNDEFINED = 0                       
              NEW = 1                             
              IN_PROCESS = 2                      
              SUCCEEDED = 3                       
              FAILED = 4                          
              TIMED_OUT = 5                       
 but for UssdQuery and UssdNotification it will   
 always be SUCCEEDED = 3                           
-->
<#if body.result == 3>
  <#switch body.ussdSC>
    <#case 121>
      <#switch body.ussdSIList[0]>
        <#case 1><#-- *121*1# display a little detail about all balances (must have subscriber balances enabled in screens)-->
          <#list body.subscriberBalanceList as bal>
            <#if bal.category == 1>
              Your ${bal.name} balance has <#if bal.availableAmount?string == "in,fin,ity">no limit<#else>${currencySymbol(bal.classId)}${bal.availableAmount} available</#if>. <#t>
            <#else>
              Your ${bal.name} balance has <#if bal.availableAmount?string == "in,fin,ity">no limit in the amount of ${bal.quantityUnit}<#else>${bal.availableAmount} ${bal.quantityUnit} available</#if>. <#t>
            </#if><#t>
          <#else>
              You have no balances!<#t>
          </#list>
          <#break>
        <#case 2><#-- *121*2 display thresholds of all balances (must have subscriber balances enabled with detail in screens)-->
          <#list body.subscriberBalanceList as bal>
            <#if bal.thresholdList?has_content>
              <#list bal.thresholdList>
                ${bal.name} balance has thresholds <#t>
                <#items as th>
                  ${th.name} <#if th.amount?string == "in,fin,ity">without limit<#else>${currencySymbol(bal.classId)}${th.amount}</#if>, <#t>
                </#items>
              </#list>
            <#else>
                ${bal.name} balance thresholds are unavailable. <#t>
            </#if>
          </#list>
          <#break>
        <#case 3><#-- *121*2*x# display balance detail of balance with classID x -->
          <#assign found=false>
          <#list body.subscriberBalanceList as bal>
            <#if bal.classId == body.ussdSIList[1]>
              <#assign found=true>
              Balance ${bal.name} has <#if bal.availableAmount?string == "in,fin,ity">no limit<#else>${currencySymbol(bal.classId)}${bal.availableAmount} available</#if>.<#lt>
              This is a ${bal.isPrepaid?switch(true, 'prepaid', false, 'postpaid')} balance, valid <#if bal.endTime?has_content>until ${bal.endTime}<#else>forever</#if>.<#t>
            </#if>
          </#list>
          <#if found == false>Unrecognised balance class id ${body.ussdSIList[1]}</#if><#t>
          <#break>
        <#default>
        Unknown SI ${body.ussdSIList[0]} for Service Code ${body.ussdSC}<#t>
      </#switch>
      <#break>
The following lines specify the USSD callback service codes 124 (for the default callback service) and 1244 (for another callback service). You can specify different callback service codes, by editing the service code cases and adding more cases:
    <#case 124>
    <#case 1244>
The following lines configure the USSD query notification messages for the USSD callback services:

    
      ${resultDetailLookup(body.resultDetail, body.authResult)}<#t>
      <#break>
  <#default>
    Unknown USSD Service code, call customer care.
  </#switch>
<#else>
  ${resultDetailLookup(body.resultDetail, body.authResult)}<#t>
</#if>
<#-- Functions -->
<#function currencySymbol x >
  <#return x?switch(826, '£', 20002, '€')>
</#function>
<#function resultDetailLookup x, y >
  <#switch x>
    <#case 0>
      <#return "In Progress \x9032\x884C\x4E2D">
      <#break>
    <#case 1>
      <#return "A-Party Answered \x767C\x96FB\x8005\x4F5C\x7B54">
      <#break>
    <#case 2>
      <#return "A-Party and B-Party Answered \x767C\x96FB\x8005\x548C\x6536\x96FB\x8005\x4F5C\x7B54">
      <#break>
    <#case 3>
      <#return "System Failure \x7CFB\x7D71\x932F\x8AA4">
      <#break>
    <#case 4>
      <#return "Unexpected or Bad message network \x7DB2\x7D61\x6D88\x606F\x932F\x8AA4">
      <#break>
    <#case 5>
      <#return "TCAP message routing error \x6D88\x606F\x8DEF\x7DDA\x932F\x8AA4">
      <#break>
    <#case 6>
      <#return "Insufficient funds \x8CC7\x91D1\x4E0D\x8DB3">
      <#break>
    <#case 7>
      <#return "Unknown calling number \x4F86\x96FB\x865F\x78BC\x4E0D\x660E">
      <#break>
    <#case 8>
      <#if y == 83>
          <#return "Only one call back at a time allowed.">
      <#else>
          <#return "Not allowed, other \x4E0D\x5141\x8A31, \x5176\x4ED6">
      </#if>
      <#break>
    <#case 9>
      <#return "Timed out \x6642\x9650\x5230">
      <#break>
    <#case 10>
      <#return "A-Party did not answer \x767C\x96FB\x8005\x4E0D\x4F5C\x7B54">
      <#break>
    <#case 11>
      <#return "A-Party Busy \x767C\x96FB\x8005\x7E41\x5FD9">
      <#break>
    <#case 12>
      <#return "Route select failure A-Party \x767C\x96FB\x8005\x8DEF\x7DDA\x932F\x8AA4">
      <#break>
    <#case 13>
      <#return "A-Party hung up before connection \x767C\x96FB\x8005\x5728\x9023\x63A5\x524D\x639B\x65B7">
      <#break>
    <#case 14>
      <#return "B-Party did not answer \x6536\x96FB\x8005\x4E0D\x4F5C\x7B54">
      <#break>
    <#case 15>
      <#return "B-Party Busy \x6536\x96FB\x8005\x7E41\x5FD9">
      <#break>
    <#case 16>
      <#return "Route select failure B-Party \x6536\x96FB\x8005\x8DEF\x7DDA\x932F\x8AA4">
      <#break>
    <#case 17>
      <#return "B-Party hung up before connection\x6536\x96FB\x8005\x5728\x9023\x63A5\x524D\x639B\x65B7">
      <#break>
    <#case 18>
      <#return "Invalid Syntax \x8A9E\x6CD5\x7121\x6548">
      <#break>
    <#case 19>
      <#return "Calling number not found \x6536\x96FB\x8005\x5728\x9023\x63A5\x524D\x639B\x6B57">
      <#break>
    <#case 20>
      <#return "B-leg has been initiated.">
      <#break>
  </#switch>
  <#return "Unknown USSD Service Code, call customer care">
</#function>