using System; using System.Collections.Generic; using System.Web.Script.Serialization; namespace Retailcrm.Versions.V3 { public partial class Client { /// /// Get manager /// /// /// /// public Response TelephonyManagerGet(string phone, string details = "1") { Dictionary parameters = new Dictionary(); if (string.IsNullOrEmpty(phone)) { throw new ArgumentException("Parameter `phone` must contains a data"); } parameters.Add("details", details); parameters.Add("phone", phone); return Request.MakeRequest("/telephony/manager", Request.MethodGet, parameters); } /// /// Send call event /// /// /// /// /// /// public Response TelephonyCallEvent(string phone, string type, string status, string code) { if (string.IsNullOrEmpty(phone)) { throw new ArgumentException("Parameter `phone` must contains a data"); } if (string.IsNullOrEmpty(code)) { throw new ArgumentException("Parameter `phone` must contains a data"); } List statuses = new List { "answered", "busy", "cancel", "failed", "no answered" }; List types = new List { "hangup", "in", "out" }; if (!statuses.Contains(status)) { throw new ArgumentException("Parameter `status` must be equal one of `answered|busy|cancel|failed|no answered`"); } if (!types.Contains(type)) { throw new ArgumentException("Parameter `type` must be equal one of `hangup|in|out`"); } return Request.MakeRequest( "/telephony/call/event", Request.MethodPost, new Dictionary { { "phone", phone }, { "type", type }, { "hangupStatus", status}, { "code", code } } ); } /// /// Upload calls /// /// /// public Response TelephonyCallsUpload(List calls) { if (calls.Count < 1) { throw new ArgumentException("Parameter `calls` must contains a data"); } if (calls.Count > 50) { throw new ArgumentException("Parameter `calls` must contain 50 or less records"); } return Request.MakeRequest( "/telephony/calls/upload", Request.MethodPost, new Dictionary { { "calls", new JavaScriptSerializer().Serialize(calls) } } ); } /// /// Edit telephony settings /// /// /// /// /// /// /// /// public Response TelephonySettingsEdit(string code, string clientId, string url, string name, string logo, string active = "true") { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Parameter `name` must contains a data"); } if (string.IsNullOrEmpty(code)) { throw new ArgumentException("Parameter `phone` must contains a data"); } if (string.IsNullOrEmpty(url)) { throw new ArgumentException("Parameter `url` must contains a data"); } if (string.IsNullOrEmpty(clientId)) { throw new ArgumentException("Parameter `clientId` must contains a data"); } return Request.MakeRequest( $"/telephony/setting/{code}", Request.MethodPost, new Dictionary { { "code", code }, { "name", name }, { "clientId", clientId}, { "makeCallUrl", url }, { "image", logo }, { "active", active } } ); } } }