org.asteriskjava.manager.action.OriginateAction Maven / Gradle / Ivy
/*
* Copyright 2004-2006 Stefan Reuter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.asteriskjava.manager.action;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.asteriskjava.manager.event.OriginateResponseEvent;
import org.asteriskjava.manager.event.ResponseEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The OriginateAction generates an outgoing call to the extension in the given
* context with the given priority or to a given application with optional
* parameters.
*
* If you want to connect to an extension use the properties context, exten and
* priority. If you want to connect to an application use the properties
* application and data if needed. Note that no call detail record will be
* written when directly connecting to an application, so it may be better to
* connect to an extension that starts the application you wish to connect to.
*
* The response to this action is sent when the channel has been answered and
* asterisk starts connecting it to the given extension. So be careful not to
* choose a too short timeout when waiting for the response.
*
* If you set async to true Asterisk reports an OriginateSuccess-
* and OriginateFailureEvents. The action id of these events equals the action
* id of this OriginateAction.
*
* @author srt
* @version $Id$
* @see org.asteriskjava.manager.event.OriginateResponseEvent
*/
public class OriginateAction extends AbstractManagerAction implements EventGeneratingAction {
private static final Logger logger = LoggerFactory.getLogger(OriginateAction.class);
private static final long serialVersionUID = 1451144273793556782L;
private String channel;
private String exten;
private String context;
private Integer priority;
private Long timeout;
private String callerId;
private Integer callingPres;
private Map variables;
private String account;
private String application;
private String data;
private Boolean async;
private String codecs;
/**
* Returns the name of this action, i.e. "Originate".
*
* @return the name of this action.
*/
@Override
public String getAction() {
return "Originate";
}
/**
* Returns the account code to use for the originated call.
*
* @return the account code to use for the originated call.
*/
public String getAccount() {
return account;
}
/**
* Sets the account code to use for the originated call.
*
* The account code is included in the call detail record generated for this
* call and will be used for billing.
*
* @param account
* the account code to use for the originated call.
*/
public void setAccount(String account) {
this.account = account;
}
/**
* Returns the caller id to set on the outgoing channel.
*
* @return callerId
*/
public String getCallerId() {
return callerId;
}
/**
* Sets the caller id to set on the outgoing channel.
*
* This includes both the Caller*Id Number and Caller*Id Name in the form
* "Jon Doe <1234>".
*
* @param callerId
* the caller id to set on the outgoing channel.
*/
public void setCallerId(String callerId) {
this.callerId = callerId;
}
/**
* Returns the calling presentation for the outgoing channel.
*
* This property is only available on BRIstuffed Asterisk servers.
*
* @return the calling presentation for the outgoing channel.
* @see #setCallingPres(Integer)
*/
public Integer getCallingPres() {
return callingPres;
}
/**
* Sets the calling presentation for the outgoing channel.
*
* The number is an octet and the only bits you need worry about are bits
* 1,2,6 and 7.
*
* Bits 1 and 2 define the screening indicator and bits 6 and 7 define the
* presentation indicator.
*
* In essence, it says, 'Is the person who has been called allowed to see
* the callers number?' (presentation) and 'What authority was used to
* verify that this is a genuine number?' (screening).
*
*
* Presentation indicator (Bits 6 and 7):
*
*
* Bits Meaning
* 7 6
* 0 0 Presentation allowed
* 0 1 Presentation restricted
* 1 0 Number not available due to interworking
* 1 1 Reserved
*
*
* Screening indicator (Bits 1 and 2):
*
*
* Bits Meaning
* 2 1
* 0 0 User-provided, not screened
* 0 1 User-provided, verified and passed
* 1 0 User-provided, verified and failed
* 1 1 Network provided
*
*
* Examples for some general settings:
*
*
* Presentation Allowed, Network Provided: 3 (00000011)
* Presentation Restricted, User-provided, not screened: 32 (00100000)
* Presentation Restricted, User-provided, verified, and passed: 33 (00100001)
* Presentation Restricted, Network Provided: 35 (00100011)
*
*
* This property is only available on BRIstuffed Asterisk servers.
*
* @param callingPres
* the calling presentation for the outgoing channel.
*/
public void setCallingPres(Integer callingPres) {
this.callingPres = callingPres;
}
/**
* Returns the name of the channel to connect to the outgoing call.
*
* @return channel number
*/
public String getChannel() {
return channel;
}
/**
* Sets the name of the channel to connect to the outgoing call.
*
* This property is mandatory.
*
* @param channel
* channel number
*/
public void setChannel(String channel) {
this.channel = channel;
}
/**
* Returns the name of the context of the extension to connect to.
*
* @return context name
*/
public String getContext() {
return context;
}
/**
* Sets the name of the context of the extension to connect to.
*
* If you set the context you also have to set the exten and priority
* properties.
*
* @param context
* context name
*/
public void setContext(String context) {
this.context = context;
}
/**
* Returns the extension to connect to.
*
* @return exten
*/
public String getExten() {
return exten;
}
/**
* Sets the extension to connect to.
*
* If you set the extension you also have to set the context and priority
* properties.
*
* @param exten
* exten
*/
public void setExten(String exten) {
this.exten = exten;
}
/**
* Returns the priority of the extension to connect to.
*
* @return priority
*/
public Integer getPriority() {
return priority;
}
/**
* Sets the priority of the extension to connect to. If you set the priority
* you also have to set the context and exten properties.
*
* @param priority
* priority
*/
public void setPriority(Integer priority) {
this.priority = priority;
}
/**
* Returns the name of the application to connect to.
*
* @return the application
*/
public String getApplication() {
return application;
}
/**
* Sets the name of the application to connect to.
*
* @param application
* the application
*/
public void setApplication(String application) {
this.application = application;
}
/**
* Returns the parameters to pass to the application.
*
* @return data
*/
public String getData() {
return data;
}
/**
* Sets the parameters to pass to the application.
*
* @param data
* data
*/
public void setData(String data) {
this.data = data;
}
/**
* Returns the timeout for the origination.
*
* @return timeout
*/
public Long getTimeout() {
return timeout;
}
/**
* Sets the timeout (in milliseconds) for the origination.
*
* The channel must be answered within this time, otherwise the origination
* is considered to have failed and an OriginateFailureEvent is generated.
*
* If not set, Asterisk assumes a default value of 30000 meaning 30 seconds.
*
* @param timeout
* the timeout in milliseconds
*/
public void setTimeout(Long timeout) {
if (timeout != null) {
if (timeout < 1000) {
logger.error(
"A timeout of 1000 will cause the originate to almost cretainly fail!");
}
if (timeout < 10000) {
logger.warn(
"A timeout of less than 100000 will cause the originate to fail if not answered within 10 seconds!");
}
}
this.timeout = timeout;
}
/**
* Sets an variable on the originated call.
*
* @param name
* the name of the variable to set.
* @param value
* the value of the variable to set.
* @since 0.3
*/
public void setVariable(String name, String value) {
if (variables == null) {
variables = new LinkedHashMap<>();
}
variables.put(name, value);
}
/**
* Returns the variables to set on the originated call.
*
* @return a Map containing the variable names as key and their values as
* value.
* @since 0.2
*/
public Map getVariables() {
return variables;
}
/**
* Sets the variables to set on the originated call.
*
* @param variables
* a Map containing the variable names as key and their
* values as value.
* @since 0.2
*/
public void setVariables(Map variables) {
this.variables = variables;
}
/**
* Returns true if this is a fast origination.
*
* @return async or not
*/
public Boolean getAsync() {
return async;
}
/**
* Set to true for fast origination. Only with fast origination Asterisk
* will send OriginateSuccess- and OriginateFailureEvents.
*
* @param async
* async or not
*/
public void setAsync(Boolean async) {
this.async = async;
}
/**
* Returns the codecs to use for the call.
*
* @return the codecs to use for the call.
* @since 1.0.0
*/
public String getCodecs() {
return codecs;
}
/**
* Sets the codecs to use for the call. For example "alaw, ulaw, h264".
*
* Available since Asterisk 1.6.
*
* @param codecs
* comma separated list of codecs to use for the call.
* @since 1.0.0
*/
public void setCodecs(String codecs) {
this.codecs = codecs;
}
/**
* Sets the codecs to use for the call.
*
* Available since Asterisk 1.6.
*
* @param codecs
* list of codecs to use for the call.
* @since 1.0.0
*/
public void setCodecs(List codecs) {
if (codecs == null || codecs.isEmpty()) {
this.codecs = null;
return;
}
Iterator iter = codecs.iterator();
StringBuilder buffer = new StringBuilder(iter.next());
while (iter.hasNext()) {
buffer.append(",")
.append(iter.next());
}
this.codecs = buffer.toString();
}
public Class extends ResponseEvent> getActionCompleteEventClass() {
return OriginateResponseEvent.class;
}
}