ForEach command

The ForEach loop command is for going through on the elements and items of an array which you can specify with the Array ID of it.

Command example usage:

It is widely used as a Voicemail functionality (for more information about the Voicemail please click here) when you would like to listen to all of your new or old messages and for example you would like to reach who was the sender of the message and when did it arrived.

Parameters:

Parameter name Value Description Mandatory
Source string value,
e.g. sampleArray
This is the ID of an array which we want to iterate in it. Yes

OzML simple example:

It deletes all of your messages from the „oldvoicemails” array.

<?xml version="1.0"?>
<Response>
	<ForEach source='sampleArray'>
	 	<speak>$item</speak>
	</ForEach>
</Response>

Detailed voicemail example:

This speaks the 2 sentences between the <InitialCommands></InitialCommands> nodes repeatedly with 5 second delay and scans the pressed numbers at the same time.

By pressing 1 the system will go through your voicemails array with the ForEach loop. You will be informed when your voicemail has been created and who was the caller. Then you will hear the record and the system will move this file into the old messages directory. That will be repeating until you have not listened to your last voicemail. If there is no more new messages the speak engine says: „You have no more new messages”.

<?xml version="1.0"?> 
<Response>
    <UserInput repeat ='true'digits ='1'>
        <InitialCommands>
            <Speak>This is the voicemail of user $username .</Speak>
            <Speak>To listen to your new messages, press 1.</Speak>
            <Delay>5</Delay>
        </InitialCommands>
        <Inputs>
            <Input key ='1'>
                <ForEach source ='voicemails'>
                    <Speak>This voicemail has been recorded at $item.date from $item.from .</Speak>
                    <Play>$item.message</Play>
                    <MoveFile SourceFile='$item.message' TargetDirectory='$oldmessagepath'></MoveFile>
                </ForEach>
                <Speak>You have no new messages.</Speak>
            </Input>
        </Inputs>
    </UserInput>
</Response>

MoveFile command is used in OzML responses to these Api Extension Control notifications:
Array, Var, Call, Hangup, SendSMS, Play, Speak

More information