REX and AIML

You can write AIML bots via the Service Management screen. Bots create dialogues based on user input. All rules for message sending (structure of each message) are described in TES API docs; violating them prevents delivery.

Using Regular Expressions

<aiml version='2.0' encoding='UTF-8'>
    <category>
        <pattern >HELLO [A-Z]+:USERNAME</pattern>
        <template >Hello 
            <get var='USERNAME'/>
        </template>
    </category>
</aiml>

If the part after HELLO matches the regex, the matched part is assigned to USERNAME and the template response is sent. The variable that receives the regex result must be uppercase.

<aiml version='2.0' encoding='UTF-8'>
    <category> 
        <pattern >BYE [A-Z]+</pattern>
        <template >Bye bye.
        </template>
    </category>
</aiml>

If the part after BYE matches the regex, the template response is sent.

Get sender info

Use <bip_sender/>

<aiml version='2.0' encoding='UTF-8' >
    <category> 
        <pattern >BYE [A-Z]+</pattern>
        <template >Bye bye.
        </template>
    </category>
</aiml>

Remembering information

Use <bip_set/> and <bip_get/>.

bip_set: Persists a value in REX with a variable name. bip_get: Retrieves a persisted value from REX using its variable name.

Usage

<bip_set var=’variableName’>variableValue</bip_set> <bip_get var=’variableName’/>

<aiml version='2.0' encoding='UTF-8' >

#### Sending Quick Reply Media Message;

```html
                            <bip_tmm_multiple_subitem_button_url>https://www.bip.ai</bip_tmm_multiple_subitem_button_url>
                        </bip_tmm_multiple_subitem_button>
                        <bip_tmm_multiple_subitem_button>
                            <bip_tmm_multiple_subitem_button_type>P</bip_tmm_multiple_subitem_button_type>
                            <bip_tmm_multiple_subitem_button_name>Button-5</bip_tmm_multiple_subitem_button_name>
                            <bip_tmm_multiple_subitem_button_payload>Payload-Button-5</bip_tmm_multiple_subitem_button_payload>
                        </bip_tmm_multiple_subitem_button>
                    </bip_tmm_multiple_subitem_button_list>
                </bip_tmm_multiple_subitem>
                <bip_tmm_multiple_subitem>
                    <bip_tmm_multiple_subitem_title>Enter title</bip_tmm_multiple_subitem_title>
                    <bip_tmm_multiple_subitem_desc>Enter description</bip_tmm_multiple_subitem_desc>
                    <bip_tmm_multiple_subitem_image>
                        <bip_tmm_multiple_subitem_image_url>https://timsac.turkcell.com.tr/scontent/p2p/14112016/11/P1e646f5c03a7b4b44f6da1329ac218e322da72356e79e5116dff86e3fc255a228.png</bip_tmm_multiple_subitem_image_url>

<bip_tmm_multiple_subitem_image_ratio>1</bip_tmm_multiple_subitem_image_ratio> </bip_tmm_multiple_subitem_image> <bip_tmm_multiple_subitem_button_list> <bip_tmm_multiple_subitem_button> <bip_tmm_multiple_subitem_button_type>I</bip_tmm_multiple_subitem_button_type> <bip_tmm_multiple_subitem_button_name>Button-6</bip_tmm_multiple_subitem_button_name> <bip_tmm_multiple_subitem_button_url>https://www.bip.ai</bip_tmm_multiple_subitem_button_url> </bip_tmm_multiple_subitem_button> <bip_tmm_multiple_subitem_button> <bip_tmm_multiple_subitem_button_type>P</bip_tmm_multiple_subitem_button_type> <bip_tmm_multiple_subitem_button_name>Button-7</bip_tmm_multiple_subitem_button_name> <bip_tmm_multiple_subitem_button_payload>Payload-Button-7</bip_tmm_multiple_subitem_button_payload> </bip_tmm_multiple_subitem_button> </bip_tmm_multiple_subitem_button_list> </bip_tmm_multiple_subitem> </bip_tmm_multiple_subitem_list> </bip_send_tmm_multiple> Payload-Button-3 M1 Payload-Button-5 M1 Payload-Button-7 M1

```
<aiml version='1.0.1' encoding='UTF-8'>

    <category>
        <pattern>tmp3</pattern>
        <template>
            <bip_send_tmm_carousel id='CRS1'>
                <bip_tmm_carousel_subitem>
                    <bip_tmm_carousel_subitem_title>Enter title</bip_tmm_carousel_subitem_title>
                    <bip_tmm_carousel_subitem_desc>Enter description</bip_tmm_carousel_subitem_desc>
                    <bip_tmm_carousel_subitem_image>
                        <bip_tmm_carousel_subitem_image_url>https://timsac.turkcell.com.tr/scontent/p2p/14112016/11/P1e646f5c03a7b4b44f6da1329ac218e322da72356e79e5116dff86e3fc255a228.png</bip_tmm_carousel_subitem_image_url>
<bip_tmm_carousel_subitem_image_ratio>1</bip_tmm_carousel_subitem_image_ratio>
                    </bip_tmm_carousel_subitem_image>
                    <bip_tmm_carousel_subitem_button_list>
                        <bip_tmm_carousel_subitem_button>
                            <bip_tmm_carousel_subitem_button_type>I</bip_tmm_carousel_subitem_button_type>
                            <bip_tmm_carousel_subitem_button_name>Button-1</bip_tmm_carousel_subitem_button_name>
                            <bip_tmm_carousel_subitem_button_url>https://www.bip.ai</bip_tmm_carousel_subitem_button_url>
                        </bip_tmm_carousel_subitem_button>
                        <bip_tmm_carousel_subitem_button>
                            <bip_tmm_carousel_subitem_button_type>P</bip_tmm_carousel_subitem_button_type>
                            <bip_tmm_carousel_subitem_button_name>Button-2</bip_tmm_carousel_subitem_button_name>
                            <bip_tmm_carousel_subitem_button_payload>Payload-Button-2</bip_tmm_carousel_subitem_button_payload>
                        </bip_tmm_carousel_subitem_button>
                    </bip_tmm_carousel_subitem_button_list>
                </bip_tmm_carousel_subitem>
                <bip_tmm_carousel_subitem>
                    <bip_tmm_carousel_subitem_title>Enter title</bip_tmm_carousel_subitem_title>
                    <bip_tmm_carousel_subitem_desc>Enter description</bip_tmm_carousel_subitem_desc>
                    <bip_tmm_carousel_subitem_image>
                        <bip_tmm_carousel_subitem_image_url>https://timsac.turkcell.com.tr/scontent/p2p/14112016/11/P1e646f5c03a7b4b44f6da1329ac218e322da72356e79e5116dff86e3fc255a228.png</bip_tmm_carousel_subitem_image_url>
<bip_tmm_carousel_subitem_image_ratio>1</bip_tmm_carousel_subitem_image_ratio>
                    </bip_tmm_carousel_subitem_image>
                    <bip_tmm_carousel_subitem_button_list>
                        <bip_tmm_carousel_subitem_button>
                            <bip_tmm_carousel_subitem_button_type>I</bip_tmm_carousel_subitem_button_type>
                            <bip_tmm_carousel_subitem_button_name>Button-3</bip_tmm_carousel_subitem_button_name>
                            <bip_tmm_carousel_subitem_button_url>https://www.bip.ai</bip_tmm_carousel_subitem_button_url>
                        </bip_tmm_carousel_subitem_button>
                        <bip_tmm_carousel_subitem_button>
                            <bip_tmm_carousel_subitem_button_type>P</bip_tmm_carousel_subitem_button_type>
                            <bip_tmm_carousel_subitem_button_name>Button-4</bip_tmm_carousel_subitem_button_name>
                            <bip_tmm_carousel_subitem_button_payload>Payload-Button-4</bip_tmm_carousel_subitem_button_payload>
                        </bip_tmm_carousel_subitem_button>
                    </bip_tmm_carousel_subitem_button_list>
                </bip_tmm_carousel_subitem>
            </bip_send_tmm_carousel>
        </template>
    </category>
    <category>
        <pattern>Payload-Button-2</pattern>
        <that type='bip_send_tmm_carousel'>CRS1</that>
        <template>Carousel de Payload-Button-2 ye basildi.</template>
    </category>
    <category>
        <pattern>Payload-Button-4</pattern>
        <that type='bip_send_tmm_carousel'>CRS1</that>
        <template>Carousel de Payload-Button-4 ye basildi.</template>
    </category>

</aiml>

Sending quick reply media messages;

 <aiml version='1.0.1' encoding='UTF-8'>

    <category>
        <pattern>tmp4</pattern>
        <template>
            <bip_send_tmm_quickreply id='QR1'>
                <bip_send_tmm_quickreply_button>
                    <bip_send_tmm_quickreply_button_name>Button-1</bip_send_tmm_quickreply_button_name>
                    <bip_send_tmm_quickreply_button_payload>Payload-Button-1</bip_send_tmm_quickreply_button_payload>
                </bip_send_tmm_quickreply_button>
                <bip_send_tmm_quickreply_button>
                    <bip_send_tmm_quickreply_button_name>Button-2</bip_send_tmm_quickreply_button_name>
                    <bip_send_tmm_quickreply_button_payload>Payload-Button-2</bip_send_tmm_quickreply_button_payload>
                </bip_send_tmm_quickreply_button>
            </bip_send_tmm_quickreply>
        </template>
    </category>
    <category>
        <pattern>Payload-Button-1</pattern>
        <that type='bip_send_tmm_quickreply'>QR1</that>
        <template>Quickreply da Payload-Button-1 ye basildi.</template>
    </category>
    <category>
        <pattern>Payload-Button-2</pattern>
        <that type='bip_send_tmm_quickreply'>QR1</that>
        <template>Quickreply da Payload-Button-2 ye basildi.</template>
    </category>
    
</aiml>

Sending single-choice poll messages;

When a poll message receives a response, you can capture it in AIML using the * notation or by using the OPTIONID_VALUE notation.

    <aiml version='1.0.1' encoding='UTF-8'>
    <category>
        <pattern>tekli-anket-secimi</pattern>
        <template>
            <bip_send_tmm_poll id='PS1'>
                <bip_tmm_poll_title>Enter title</bip_tmm_poll_title>
                <bip_tmm_poll_desc>Enter description</bip_tmm_poll_desc>
                <bip_tmm_poll_type>S</bip_tmm_poll_type>
                <bip_tmm_poll_time>12.08.2017 17:36:50.116 +0300</bip_tmm_poll_time>
                <bip_tmm_poll_buttonname>Button-1</bip_tmm_poll_buttonname>
                <bip_tmm_poll_option_list>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-0</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>0</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-1</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>1</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-2</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>2</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-3</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>3</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                </bip_tmm_poll_option_list>
                <bip_tmm_poll_image>
                    <bip_tmm_poll_image_url>https://timsac.turkcell.com.tr/scontent/p2p/14112016/11/P1e646f5c03a7b4b44f6da1329ac218e322da72356e79e5116dff86e3fc255a228.png</bip_tmm_poll_image_url>
<bip_tmm_poll_image_ratio>1</bip_tmm_poll_image_ratio>
                    <bip_tmm_poll_image_ratio>1</bip_tmm_poll_image_ratio>
                </bip_tmm_poll_image>
            </bip_send_tmm_poll>
        </template>
    </category>
    
    <category>
        <pattern>0</pattern>
        <that type='bip_send_tmm_poll'>PS1</that>
        <template>Tekli anket secimi: option-1 secildi.</template>
    </category>
    <category>
        <pattern>*</pattern>
        <that type='bip_send_tmm_poll'>PS1</that>
        <template>Tekli anket secimi: <star/> secildi. 
        </template>
    </category>
    
</aiml>

Sending multiple-choice poll messages;

When an answer arrives, you can capture it with <pattern>*</pattern> or with <pattern>OPTIONID_VALUE</pattern>. To capture multiple selections at once, you can use a Regular Expression inside <pattern />.

   <aiml version='1.0.1' encoding='UTF-8'>
    
    <category>
        <pattern>multiple-poll-selection</pattern>
        <template>
            <bip_send_tmm_poll id='PM1'>
                <bip_tmm_poll_title>Enter title</bip_tmm_poll_title>
                <bip_tmm_poll_desc>Enter description</bip_tmm_poll_desc>
                <bip_tmm_poll_type>M</bip_tmm_poll_type>
               <bip_tmm_poll_time>12.08.2017 17:36:50.116 +0300</bip_tmm_poll_time>
                <bip_tmm_poll_buttonname>Button-1</bip_tmm_poll_buttonname>
                <bip_tmm_poll_option_list>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-1</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>0</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-2</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>1</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-3</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>2</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                    <bip_tmm_poll_option>
                        <bip_tmm_poll_option_text>option-4</bip_tmm_poll_option_text>
                        <bip_tmm_poll_option_id>3</bip_tmm_poll_option_id>
                    </bip_tmm_poll_option>
                </bip_tmm_poll_option_list>
                <bip_tmm_poll_image>
                    <bip_tmm_poll_image_url>https://timsac.turkcell.com.tr/scontent/p2p/14112016/11/P1e646f5c03a7b4b44f6da1329ac218e322da72356e79e5116dff86e3fc255a228.png</bip_tmm_poll_image_url>
<bip_tmm_poll_image_ratio>1</bip_tmm_poll_image_ratio>
                </bip_tmm_poll_image>
            </bip_send_tmm_poll>
        </template>
    </category>
    <category>
        <pattern>^(?=.*?(0))(?=.*?(1))(?=.*?(2))(?=.*?(3)).* #x3C;</pattern>
        <that type='bip_send_tmm_poll'>PM1</that>
        <template>Multiple selection poll: option-1 option-2 option-3 option-4 selected.</template>
    </category>
    <category>
        <pattern>^(?=.*?(0))(?=.*?(1))(?=.*?(2)).*#x3C;</pattern>
        <that type='bip_send_tmm_poll'>PM1</that>
        <template>Multiple selection poll: option-1 option-2 option-3 selected.</template>
    </category>
    <category>
        <pattern>^(?=.*?(0))(?=.*?(1)).*#x3C;/pattern>
        <that type='bip_send_tmm_poll'>PM1</that>
        <template>Multiple selection poll: option-1 option-2 selected.</template>
    </category>
    <category>
        <pattern>0</pattern>
        <that type='bip_send_tmm_poll'>PM1</that>
        <template>Multiple selection poll: option-1 selected.</template>
    </category>
    <category>
        <pattern>*</pattern>
        <that type='bip_send_tmm_poll'>PM1</that>
        <template>Multiple selection poll: <star/> selected.</template>
    </category>
</aiml>

Use an “ID” value so AIML can match the responses via THAT. The ID must not exceed five characters.

    <category>
        <pattern>consent_simple</pattern>
        <template>
            <bip_send_consent id='c_s1' >
                <bip_consent_message>Consent Simple question: Do you approve?</bip_consent_message>
                <bip_consent_reject_button>No</bip_consent_reject_button>
                <bip_consent_approval_button>Yes</bip_consent_approval_button>
            </bip_send_consent>
        </template>
    </category>
	
    <category>
        <pattern>No</pattern>
        <that type='bip_send_consent'>c_s1</that>
        <template>The No button was clicked on the Consent Simple question.</template>
    </category>
	
    <category>
        <pattern>Yes</pattern>
        <that type='bip_send_consent'>c_s1</that>
        <template>The Yes button was clicked on the Consent Simple question.</template>
    </category>
</aiml>
<aiml version='1.0.1' encoding='UTF-8'>

    <category>
        <pattern>consent_input</pattern>
        <template>
            <bip_send_consent id='c_i1' consent_input='consent_input_variable'>
                <bip_consent_message>Consent Input question: Do you approve?</bip_consent_message>
                <bip_consent_reject_button>No</bip_consent_reject_button>
                <bip_consent_approval_button>Yes</bip_consent_approval_button>
            </bip_send_consent>
        </template>
    </category>
	
    <category>
        <pattern>No</pattern>
        <that type='bip_send_consent'>c_i1</that>
        <template>
            Thank you for providing <get name='consent_input_variable'/>. The No button was clicked on the Consent Input question.
        </template>
    </category>
	
    <category>
        <pattern>Yes</pattern>
        <that type='bip_send_consent'>c_i1</that>
        <template>
            Thank you for providing <get name='consent_input_variable'/>. The Yes button was clicked on the Consent Input question.
        </template>
    </category>
</aiml>

Receiving LOCATION, IMAGE, VIDEO, AUDIO, CAPS, or STICKER messages from users;

<aiml version='1.0.1'>

    <category>
        <pattern type='LOCATION'></pattern>
        <template>LOCATION received. Details: <bip_incoming_message field='latitude' /> | <bip_incoming_message field='longitude' /> | <bip_incoming_message field='title' /> | <bip_incoming_message field='desc' /></template>
    </category>

    <category>
        <pattern type="MEDIA">IMAGE</pattern>
        <template>IMAGE received. Details: <bip_incoming_message field='message' /></template>
    </category> 

    <category>
        <pattern type="MEDIA">VIDEO</pattern>
        <template>VIDEO received. Details: <bip_incoming_message field='message' /></template>
    </category>

    <category>
        <pattern type="MEDIA">AUDIO</pattern>
        <template>AUDIO received. Details: <bip_incoming_message field='message' /></template>
    </category>

    <category>
        <pattern type="MEDIA">STICKER</pattern>
        <template>STICKER received. Details: <bip_incoming_message field='message' /></template>
    </category>


    <category>
        <pattern type="MEDIA">CAPS</pattern>
        <template>CAPS received. Details: <bip_incoming_message field='message' /></template>
    </category>


    <category>
        <pattern type="MEDIA">ALL</pattern>
       <template>If you do not define a specific category in AIML for IMAGE/VIDEO/AUDIO/CAPS/STICKER, this catch-all category matches.</template>
    </category>
</aiml>

Sending location, image, or audio messages to users

<aiml version='1.0.1'>
    <category>
        <pattern>image</pattern>
        <template>
            <bip_send_image>
                <bip_send_image_url>https://.....jpg</bip_send_image_url>
            </bip_send_image>
        </template>
    </category>

    <category>
        <pattern>audio</pattern>
        <template>
            <bip_send_audio>
                <bip_send_audio_url>https://.....mp3</bip_send_audio_url>
            </bip_send_audio>
        </template>
    </category>

    <category>
        <pattern>location</pattern>
        <template>
            <bip_send_location>
                <bip_send_location_latitude>40.9552494</bip_send_location_latitude>
                <bip_send_location_longitude>29.1181094</bip_send_location_longitude>
                <bip_send_location_description>optional desc</bip_send_location_description>
                <bip_send_location_title>optional title</bip_send_location_title>
            </bip_send_location> 
        </template>
    </category>    
</aiml>

POI lookup

bip_poi_unit accepts either m or km. Use m for meters and km for kilometers in AIML. When you omit it, the default is m.

bip_poi_number_of_responses accepts a maximum of 5 values. The default is 3 when not specified.

bip_poi_distance defaults to 500 if you do not provide another value.

<aiml version='1.0.1'>
 <category>
  <pattern>poi</pattern>
  <template>Please send your location.</template>
 </category>
 <category>
  <pattern type='LOCATION'></pattern>
  <that>Please send your location.</that>
  <template>
   <think>
    <set var='Lat'><bip_incoming_message field='latitude' /></set>
    <set var='lon'><bip_incoming_message field='longitude' /></set>
   </think>

   <bip_query_poi query_result='operationResult' query_response='poiList' query_response_count='poiListCount'>
    <bip_poi_latitude><get var='Lat' /></bip_poi_latitude>
    <bip_poi_longitude><get var='lon' /></bip_poi_longitude>
    <bip_poi_category />
    <bip_poi_number_of_responses />
    <bip_poi_unit />
    <bip_poi_distance />
   </bip_query_poi>

   <condition var='operationResult'>
    <li value='unknown'>AIML syntax error: the variable named operationResult is missing.</li>
    <li value='false'>The operation could not be completed. There was a connection problem with the system being queried.</li>
    <li value='true'>
     <condition var='poiListCount'>
      <li value='unknown'>AIML syntax error: the variable named poiListCount is missing.</li>
      <li value='0'>No suitable POI was found.</li>
      <li>
       Hello. The closest POIs are:
       <bip_send_contents var='poiList' />
      </li>
     </condition>
    </li>
   </condition>
  </template>
 </category>
</aiml>

Welcome message for new followers

This event fires when a BiP user starts following the service. Define it in AIML as <pattern type='event'>WELCOME</pattern>.

<aiml version='2.0'>
 <category>
  <pattern type='event'>WELCOME</pattern>
  <template>
   <bip_richmedia_poll id='12345'>
    <bip_description>Hello. Please choose from the menu.</bip_description>
    <bip_title>Bot-sent welcome message for the new follower</bip_title>
    <bip_polltime>35</bip_polltime>
    <bip_option>option 1</bip_option>
    <bip_option>option 2</bip_option>
   </bip_richmedia_poll>
  </template>
 </category>

 <category>
  <pattern>option 1</pattern>
  <that type='bip_richmedia_poll'>12345</that>
  <template>option 1 selected</template>
 </category>

 <category>
  <pattern>option 2</pattern>
  <that type='bip_richmedia_poll'>12345</that>
  <template>option 2 selected</template>
 </category>
</aiml>

When a follower unfollows the service

This event triggers when a BiP user stops following the service. Define it in AIML as <pattern type='event'>UNFOLLOW</pattern>.

<aiml version='1.0.1' encoding='UTF-8'>
 <category>
  <pattern type='event'>UNFOLLOW</pattern>
  <template>
   <think>Since the user unfollowed the service, you cannot send messages but you may still perform other operations.</think>
  </template>
 </category>
</aiml>

Warm welcome message for chat

This message is sent when the user opens their existing conversation with the service. For more details, see the TES API documentation. Define it in AIML as <pattern type='event' minIdleTime='1' frequency='D'>WARM_WELCOME</pattern>.

  • Frequency: optional parameter.

  • Values: D/W, where D means Daily and W means Weekly.

    Frequency defaults to sending the message every time the chat screen opens, with at least 1 minute between repetitions.

    D (Day): Sends the message once per day when the chat screen opens. It will not send again until the next day at 00:01.

    W (Week): Sends the message once per week when the chat screen opens. It will not send again until the following Monday at 00:01.

    minIdleTime: Must be at least 1 minute. This defines how much idle time must pass since the user’s last interaction before the message reappears. It defaults to 1 minute when omitted.

<aiml version='2.0'>
 <category>
  <pattern type='event' minIdleTime='1' frequency='D' >WARM_WELCOME</pattern>
  <template>
   <bip_richmedia_poll id='12345'>
    <bip_image>https://timsac.turkcell.com.tr/scontent/p2p/14112016/11/P1e646f5c03a7b4b44f6da1329ac218e322da72356e79e5116dff86e3fc255a228.png</bip_image>
    <bip_description>Hello. Please choose from the menu.</bip_description>
    <bip_title>Bot-sent warm welcome message for the chat</bip_title>
    <bip_polltime>35</bip_polltime>
    <bip_option>option 1</bip_option>
    <bip_option>option 2</bip_option>
   </bip_richmedia_poll>
  </template>
 </category>
 <category>
  <pattern>option 1</pattern>
  <that type='bip_richmedia_poll'>12345</that>
  <template>option 1 selected</template>
 </category>
 <category>
  <pattern>view option 2</pattern>
  <that type='bip_richmedia_poll'>12345</that>
  <template>option 2 selected</template>
 </category>
</aiml>

Calling an external web service from AIML

AIML can invoke an external web service to perform operations whose results come from another system. Use bip_webservice_call and bip_webservice_query for these integrations. Use bip_webservice_call when the synchronous web service response should be sent directly to the user, and use bip_webservice_query when you need to inspect or otherwise process the response inside AIML before acting.

bip_webservice_call: Calls the external web service and forwards the synchronous response back to the user.

bip_parameter: Enables you to pass dynamic parameters as key/value pairs when AIML calls the external web service.

bip_webservice_call_result: Signals the status of the operation (true or false). It returns false if the external service is unreachable or if the HTTP status code is not 200.

Use the host attribute to give AIML the external WS URL. The target service must be accessible over port 80 or 443.

<aiml version='2.0' encoding='UTF-8'>
 <category>
  <pattern>*</pattern>
  <template>
   <bip_webservice_call host="EXTERNAL_WS_URL">
    <bip_parameter name='sorguTipi'>doviz</bip_parameter>
    <bip_parameter name='dovizTipi'>*</bip_parameter>
    <bip_webservice_call_result var='wscallresult' />
   </bip_webservice_call>

   <condition var='wscallresult'>
    <li value='false'><srai>EXTWS_ERROR</srai></li>
   </condition>

  </template>
 </category>

 <category>
  <pattern>EXTWS_ERROR</pattern>
  <template>Unable to connect to the external system or an error occurred. In short, http-status-code != 200</template>
 </category>
</aiml>

bip_webservice_query: Calls the external web service and hands the synchronous response back to AIML. The bot author decides how to handle the returned data inside AIML.

bip_parameter: Allows key/value dynamic parameters to be passed when communicating with the external web service.

bip_webservice_query_result: Reports whether the remote call succeeded (true or false). It returns false if the external service is unreachable or the HTTP status code is not 200.

bip_webservice_query_response: Stores the returned response in a variable that AIML can inspect.

bip_webservice_query_response_size: Indicates how many content items are inside the returned composition. The response follows the same composition structure and can include one or more contents (TEXT, MEDIA, or RICHMEDIA).

bip_composition: Iterates over the composition structure received from the external service. Use it together with bip_content to loop over the content entries—with <loop /> you can traverse them as if in a for-loop.

bip_content: Accesses each content entry inside the composition. Each entry exposes type and message.

bip_field: Use this to read the details of a content entry obtained via bip_content, such as the type and message fields. Currently only TEXT (type=0) replies are supported, so use the message field to read the text content.

Use the host attribute to provide the external WS URL. The target service must be reachable over port 80 or 443.

  <aiml version='2.0'>

 <category>
  <pattern>*</pattern>
  <template>

   <bip_webservice_query host="EXTERNAL_WS_URL">
    <bip_parameter name="action">askPaymentType</bip_parameter>
    <bip_webservice_query_result var="wscallsucceed" />
    <bip_webservice_query_response var="syncresponselist" />
    <bip_webservice_query_response_size var="syncresponselistsize" />   
   </bip_webservice_query>

   <condition var="wscallsucceed">

    <li value="false"><srai>EXTWS_ERROR</srai></li>
    <li value="true">

     <condition var="syncresponselistsize">
      <li value="0"><srai>EXTWS_NORESPONSE</srai></li>
      <li>
       <bip_composition var="syncresponselist">
        <bip_content var="syncresponse">
         <think>
          <set var="type">
           <bip_field var="syncresponse" field="type" />
          </set>
         </think>
         <condition var="type">
          <li value="0">
           <think>
            <set var="text"><bip_field var="syncresponse" field="message" /></set>
           </think>
           <condition var="text">
            <li value="POSTPAID"><srai>POSTPAID_MENU</srai></li>
            <li>The format is correct but unexpected content arrived. Received content: <get var="text" /></li>
           </condition>
          </li>
          <li><srai>EXTWS_RESPONSE_FORMAT_ERROR</srai></li>
         </condition>
         <loop />
        </bip_content>
       </bip_composition>
      </li>
     </condition>
    </li>
   </condition>
  </template>
 </category>

 <category>
  <pattern>POSTPAID_MENU</pattern>
  <template>
   <bip_richmedia_poll id='12345'>
    <bip_image>https://timsac.turkcell.com.tr/scontent/p2p/14112016/11/P1e646f5c03a7b4b44f6da1329ac218e322da72356e79e5116dff86e3fc255a228.png</bip_image>
    <bip_description>Please choose the operation you want to perform.</bip_description>
    <bip_title>Call Center</bip_title>
    <bip_polltime>35</bip_polltime>
    <bip_option>Tariff and Package</bip_option>
    <bip_option>Billing Services</bip_option>
   </bip_richmedia_poll>
  </template>
 </category>

 <category>
  <pattern>Tariff and Package</pattern>
  <that type='bip_richmedia_poll'>12345</that>
  <template>The tariff and package menu is under construction.</template>
 </category>

 <category>
  <pattern>Billing Services</pattern>
  <that type='bip_richmedia_poll'>12345</that>
  <template>The billing services menu is under construction.</template>
 </category>

 <category>
  <pattern>EXTWS_ERROR</pattern>
  <template>Unable to connect to the external system or it returned an error. In short, http-status-code != 200</template>
 </category>

 <category>
  <pattern>EXTWS_NORESPONSE</pattern>
  <template>The external system returned a response, but it is null or empty.</template>
 </category>

 <category>
  <pattern>EXTWS_RESPONSE_FORMAT_ERROR</pattern>
  <template>The external system returned a response, but it uses a format other than the expected TEXT type.</template>
 </category>

</aiml>

Using the user message inside AIML

Use <bip_incoming_message/> to access the message sent to the service. You can forward the incoming content to an external WS as a dynamic parameter, as shown in the following AIML snippet.

<aiml version='1.0.1' encoding='UTF-8'>

    <category>
        <pattern type='MEDIA'>incoming</pattern>
        <template>
            <bip_webservice_call host='https://127.0.0.1:80/test/botapi/extws/8140'>
                <bip_parameter name='incomingMessage'>
                    <bip_incoming_message/>
                </bip_parameter>
                <bip_webservice_call_result name='wscallresult'/>
            </bip_webservice_call>
            <condition name='wscallresult'>
                <li value='false'>The WS call failed.</li>
            </condition>
        </template>
    </category>

</aiml>

If the user sends an image file to the service and AIML is written as shown above, the following JSON request is sent to the external WS:

{ 
   "transferData":{ 
      "incomingMessage":{ 
         "type":2,
         "message":"https://testtims.turkcell.com.tr/scontent/p2p/20022017/08/P86e9df4f4e9148672681e0cfbd15a6bcb05c5b17f94ef6645829cc77d2b3be2f11.jpg"
      }
   },
   "msgId":"0ea091ac-374e-437e-8966-d5d45b77d4e3_74 ",
   "serviceId":8140
}

Handling responses to BiPUssu Panel bulk transmissions inside AIML

The that command must be typed as type='bipussu_bulk_transmission'. When you want to handle a specific transmission in AIML, set the that value to include the unique transmission name.

<aiml version='1.0.1' encoding='UTF-8'>

    <category>
        <pattern>*</pattern>
        <that type='bipussu_bulk_transmission'>UNIQUE-BULK-TRANSMISSION-NAME</that>
        <template>Response to the transmission named UNIQUE-BULK-TRANSMISSION-NAME:
            <star/>
        </template>
    </category>    	
</aiml>

If you want AIML to catch the response for any transmission, set the that value to include ALL.

<aiml version='1.0.1' encoding='UTF-8'>
    <category>
        <pattern>*</pattern>
        <that type='bipussu_bulk_transmission'>ALL</that>
        <template>Response given to other campaigns: 
            <star/>
        </template>
    </category>
</aiml>