简体   繁体   中英

How to set RingCentral hold music?

RingCentral has the ability to upload custom Hold Music via the UI. Can this be done via the API, as user and as an admin for other users? Searching the API Reference for hold music didn't turn up an API.

Here's some info on this functionality:

Here's what the UI looks like:

在此处输入图片说明

There are two steps to this:

  1. Get the Answering Rule ID of the rule you want to change. This can be a standard rule such as business-hours-rule , or it can be a custom rule that you have created. You can call the Get Call Handling Rules API to get a list of current standard and custom rules.
  2. Call the Update Greeting API with type set to HoldMusic and answeringRuleId set to the id you wish to update, eg business-hours-rule

There are actually several ways to call the Update Greeting API:

  1. multipart/form-data with individual string parts. In this approach, separate parts are sent with names type , answeringRuleId , and binary
  2. multipart/form-data with JSON metadata part. In this approach, a JSON MIME part named json is sent with a payload like: {"type": "HoldMusic", "answeringRule": { "id": "12345678" }}
  3. multipart/mixed

I tend to prefer the first approach ( multipart/form-data with individual string parts) because it's easy to use with tools like cURL and many HTTP clients.

Here's an example using Go:

package main

import(
    "log"
    "net/http"
    "net/url"
    "os"

    "github.com/grokify/gotilla/mime/multipartutil"
    "github.com/grokify/oauth2more/ringcentral"
)

func main() {

    // Get the Client (*http.Client):
    client, err = ringcentral.NewClientPassword(
        ringcentral.ApplicationCredentials{
            ClientID:     os.Getenv("RINGCENTRAL_CLIENT_ID"),
            ClientSecret: os.Getenv("RINGCENTRAL_CLIENT_SECRET"),
            ServerURL:    os.Getenv("RINGCENTRAL_SERVER_URL")},
        ringcentral.PasswordCredentials{
            Username:  os.Getenv("RINGCENTRAL_USERNAME"),
            Extension: os.Getenv("RINGCENTRAL_EXTENSION"),
            Password:  os.Getenv("RINGCENTRAL_PASSWORD")})
    if err!=nil {
        log.Fatal(err)
    }

    // Create the HTTP Request (*http.Request)
    params := url.Values{}
    params.Set("type", "HoldMusic")
    params.Set("answeringRuleId", "business-hours-rule")

    req, err := multipartutil.NewRequest(
        http.MethodPost,
        "https://platform.ringcenral.com/restapi/v1.0/account/~/extension/~/greeting",
        params,
        []multipartutil.FileInfo{
            {
                MIMEPartName: "binary",
                Filepath:     "mygreeting.wav",
            },
        },
    )

    // Send the request
    resp, err = client.Do(req)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("STATUS: %v\n", resp.StatusCode) 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM