找回密码
 注册

QQ登录

只需一步,快速开始

查看: 701|回复: 1

Dial Plans used to dial out Google Voice through SIP Sorcery

[复制链接]
发表于 2011-11-16 16:27:53 | 显示全部楼层 |阅读模式
本帖最后由 Test 于 2011-11-17 09:39 编辑

Introduction
        SIP Sorcery dial plans are what control how calls are processed. A dial plan is required for outgoing calls to be processed, without it the SIP Sorcery server would not know how you wanted your calls to be forwarded. A dial plan is optional for incoming calls. If a SIP account does not have an incoming dial plan specified then the default behaviour is to forward the call to all registered bindings for that account.
        The SIP Sorcery dial plans are written as Ruby scripts. The SIP Sorcery application server exposes a wide range of functions that  can be called in dial plan scripts to place calls, send emails, send instant messages, retrive and set values from a database and many more.
         
sys.Dial        
Usage:

        DialPlanAppResult sys.Dial(string dialString)
        DialPlanAppResult sys.Dial(string dialString, int ringTimeout)
        DialPlanAppResult sys.Dial(string dialString, int ringTimeout, int answeredCallLimit)

Description:
          The most important dial plan function. Initiates a call to one or more SIP end points and when the first call is answered will bridge it with the SIP user agent that initiated the application. The Dial command takes a dial string as a parameter and it controls the order, delay and other types of behaviours for the forwarded call requests. The syntax of the dial string is best demonstrated by an example:
  1. # sys.Dial example.
  2. sys.Dial("123@provider1&456@provider2[dt=5]|789@provider3")  
复制代码
                           
  • A call will be placed to 123@provider1,
  • After a 5 second delay a call will be placed to 456@provider2,
  • If both calls fail a call will be placed to 789@provider3.

If at any point one of the forwards answered all other forwards are cancelled and the dialplan execution terminates. The additional options that can be used on each call leg are:
  1. # sys.Dial example.
  2. sys.Dial("123@provider1[rm=a,cd=3600]&456@provider2[dt=5,rm=a,cd=600]")
复制代码

                                
  • dt: Delay call start in seconds,
  • cd: Answered call duration in seconds,
  • rm: Redirect mode, n=Process redirects in a new instance of the same dial plan.
  • ma: Whether to mangle the SDP, true or false (default is true so use this to specify no mangling on a call leg).
  • fd: Sets a custom From header display name for this call leg,
  • fu: Sets a custom From header URI username for this call leg,
  • fh: Sets a custom From header URI host for this call leg,
  • tr: Determines whether transfers (REFER requests) will be accepted: n=Not permitted, p=Pass thru (default), c=Place call (be careful!)

sys.Log            
Usage:
            sys.Log(string logMessage)
            Description:
                                    Logs a message that will be displayed on the console and email traces. This is an essential function to provide troubleshooting or general            information about the state of a dial plan as it processes a call.            
            ?
1
2
# sys.Log example.
sys.Log("Log message from the SIP Sorcery dial plan.")</div>



                        sys.GoogleVoiceCall            Usage:
                            sys.GoogleVoiceCall(string emailAddress, string password,                  string forwardingNumber, string destinationNumber,                  string fromUserToMatch, int phoneType, int callbackTimeout)
            Description:
            A popular dial plan function that can be used to initiate calls using Google's Google Voice service. The application works by            sending a HTTP request to Google Voice that in turn initiates a callback. The incoming call leg must reach the same SIP Sorcery account that the Google Voice call is being            placed for. Once the incoming callback is received it will be matched to the SIP call leg that initiated it.
            ?
1
2
# sys.GoogleVoice example.
sys.GoogleVoice("user@gmail.com", "password", "12345670000", "76543210000", ".*", 1, 30)



            
  • The emailAddress and password are the credentials used to login to the Google Voice portal.
  • The forwardingNumber is the number to request the Google Voice callback on. Whatever this number is it needs to get the call to SIPSorcery.
  • The destinationNumber is the number that will be passed to the callback as the outgoing leg and is the external number that will be called.
  • The fromUserToMatch is used to match the incoming callback to the SIP call that initiated the dial plan execution. By specifying this field                    sipsorcery will look at the From URI user, in a SIP From header of From: "Joe Bloggs" <sip:12345678@somehost.com> the From URI user is 12345678,                    to match the calls.
  • The phone type used by GoogleVoice. If not specified defaults to (Mobile=2):
    • 1 - Home
    • 2 - Mobile
    • 3 - Work
                
  • The callback timeout in seconds which is the amount of time the sipsorcery dialplan will wait for the GoogleVoice callback before giving up and                continuing with the next dialplan command. The timeout must be between 5 and 60s and if not specified a default value of 30s is used.
            
                            



 楼主| 发表于 2011-11-16 16:28:14 | 显示全部楼层
sys.WebGet                Usage:
                        string sys.WebGet(string url)
                             Description:
                           Sends an HTTP GET request and returns the result to the dialplan.
            ?
1
2
# sys.WebGet example.
result = sys.WebGet("https://www.sipsorcery.com/callmanager.svc/isalive")



                                         Database Functions              Usage:
             sys.DBWrite(string key, string value) # Writes a keyed value to the database.
                string sys.DBRead(string key) # Reads a keyed value from the database.
             sys.DBDelete(string key) # Deletes a keyed value from the database.
                            Description:
              ?
1
2
3
4
# Database read, write and delete example.
sys.DBWrite("myKey", "myValue")
val = sys.DBRead("myKey")
sys.DBDelete("myKey")



                         SIP Header and Request manipulation functions              Usage:
              sys.SetCustomSIPHeader(string header, string value) # Sets a custom SIP header that will be added to all subsequent calls.
               sys.RemoveCustomSIPHeader(string header) # Removes the custom SIP header from the list.
              sys.ClearCustomSIPHeaders() # Clears all custom SIP headers from the list.
              sys.PrintCustomSIPHeaders() # Prints custom SIP headers to the monitoring console.
              sys.SetFromHeader(string fromName, string fromUser, string fromHost) #  Sets the SIP Fromheader that will be used for all subsequent calls.
              sys.ClearFromHeader() # Resets the From SIP header.
              sys.SetCustomContent(string contentType, string content) # Sets the Content-Type SIP header and the body that will be used for all subsequent call requests.
              sys.ClearCustomBody() # Resets the custom Content-Type SIP header and the body.
              Description:
                        The SetFromHeader method is the most useful of the above methods as the SIP From header is what typically translates to caller ID on a SIP call. By customising the SIP From            header the caller ID displayed on the callee's phone can be modified. However most SIP Providers use the SIP From header for authentication and modifying it, and in particular the             fromUser parameter can cause the call to fail. When caller ID manipulation is required it's recommended to start by only modifying the fromName parameter             and only if that doesn't have the desired effect look at modifying the fromUser parameter; the fromHost should only need to be set in rare circumstances.
            ?
1
2
# Set CallerID example.
sys.SetFromHeader("Mr Big", nil, nil)



                        sys.Email              Usage:
             sys.Email(string to, string subject, string body)
                          Description:
                        Sends an email the address specified in the to parameter.            
            ?
1
2
# Send email example.
sys.Email("admin@sipsorcery.com", "Email from Dial Plan", "Hello World!")



                        SIP Account, Call and Domain query functions             Usage:
            int sys.GetCurrentCallCount() # Returns the number of calls currently in progress.
             List<SIPDialogueAsset> sys.GetCurrentCalls() # Returns a list of currently active calls.
            bool sys.DoesSIPAccountExist(string username, string domain) # Returns true if the specified SIP Account exists on the system, false otherwise.
            string GetCanonicalDomain(string host) # Test whether a string represents a domain serviced by SIP Sorcery. Returns the canonical            domain for the host string if it is or nil if not.
            SIPRegistrarBinding[] GetBindings(string username, string domain) # Gets an array of the registered contacts for a specified SIP account. You must be the owner of the SIP account.
            bool sys.IsAvailable(string username, string domain) # Checks whether the specified SIP account is online (has any current bindings).
            Description:
                   ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# sys.GetCurrentCallCount example.
mycallCount = sys.GetCurrentCallCount()
sys.Log("My current call count is #{myCallCount}.")

# sys.GetCurrentCalls example.
sys.GetCurrentCalls().each { |call|
  sys.Log("remote user field = " + call.RemoteUserField)
}

# sys.GetCanonicalDomain example.
domain = sys.GetCanonicalDomain("sip1.sipsorcery.com:5060")
sys.Log("Canonical domain is #{domain}.") if domain != nil

# sys.DoesSIPAccountExist example.
exists = sys.DoesSIPAccountExist("myaccount", "sipsorcery.com")
# Omitting the domain parameter causes it to default to sipsorcery.com.
exists = sys.DoesSIPAccountExist("myaccount", nil)

# sys.GetBindings example.
bindings = sys.GetBindings("myaccount", "sipsorcery.com")
if bindings != nil then
  bindings.each { |binding|
    sys.Log("binding contact=#{binding.ContactURI.ToString()}")
  }
end

# sys.IsAvailable example.
if sys.IsAvailable("myaccount", "sipsorcery.com") then
  sys.Dial("myacount")
else
  sys.Respond(480, "Sorry no one available")
end



                        
http://www.sipsorcery.com/mainsite/Help/DialPlans
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )

GMT-8, 2026-5-28 12:13 , Processed in 0.016802 second(s), 16 queries .

Supported by Weloment Group X3.5

© 2008-2026 Best Deal Online

快速回复 返回顶部 返回列表