有两个步骤:
- 获取要更改的规则的应答规则 ID。这可以是标准规则,例如
business-hours-rule,也可以是您创建的自定义规则。您可以调用获取呼叫处理规则 API 以获取当前标准和自定义规则的列表。
- 调用 Update Greeting API,将
type 设置为 HoldMusic 并将 answeringRuleId 设置为您要更新的 id,例如business-hours-rule
实际上有几种方法可以调用 Update Greeting API:
-
multipart/form-data 带有单独的字符串部分。在这种方法中,单独的部分以名称type、answeringRuleId 和binary 发送
-
multipart/form-data 带有 JSON 元数据部分。在这种方法中,一个名为 json 的 JSON MIME 部分与如下负载一起发送:{"type": "HoldMusic", "answeringRule": { "id": "12345678" }}
multipart/mixed
我更喜欢第一种方法(multipart/form-data 带有单独的字符串部分),因为它很容易与 cURL 和许多 HTTP 客户端等工具一起使用。
这是一个使用 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)
}