// Send the fax and return the ApiResponse object public static ApiResponse SendFax(SDK sdk) { // Get Cover Page var coverPage = GetCoverPage (); // Get Fax Body var attachmentBytes = File.ReadAllBytes (Environment.GetEnvironmentVariable ("RC_DEMO_FAX_FILEPATH")); var attachment = new Attachment ("example.pdf", "application/pdf", attachmentBytes); var attachments = new List<Attachment> {coverPage, attachment}; var to = Environment.GetEnvironmentVariable ("RC_DEMO_FAX_TO"); var json = "{\"to\":[{\"phoneNumber\":\"" + to + "\"}],\"coverIndex\":\"0\"}"; Request request = new Request ("/restapi/v1.0/account/~/extension/~/fax", json, attachments); ApiResponse response = sdk.Platform.Post(request); return response; }
public void Fax() { var requestBody = JsonConvert.SerializeObject(new { faxResolution = "High", coverIndex = 0, to = new object[] { new { phoneNumber = Config.Instance.Receiver } } }); var attachments = new List<Attachment>(); var textBytes = System.Text.Encoding.UTF8.GetBytes("hello fax"); var attachment = new Attachment(@"test.txt", "application/octet-stream", textBytes); attachments.Add(attachment); var request = new Request("/restapi/v1.0/account/~/extension/~/fax", requestBody, attachments); var body = request.HttpContent; Assert.NotNull(body); var response = sdk.Platform.Post(request); Assert.AreEqual(true, response.OK); }
// Get the coverpage as a RingCentral.Http.Attachment object public static Attachment GetCoverPage() { var templatePath = Environment.GetEnvironmentVariable ("RC_DEMO_FAX_COVERPAGE_TEMPLATE"); var source = File.ReadAllText (templatePath); var template = Handlebars.Compile (source); Dictionary<string, string> data = new Dictionary<string, string>() { {"fax_date", ""}, {"fax_pages", Environment.GetEnvironmentVariable ("RC_DEMO_FAX_PAGES")}, {"fax_to_name", Environment.GetEnvironmentVariable ("RC_DEMO_FAX_TO_NAME")}, {"fax_to_fax", Environment.GetEnvironmentVariable ("RC_DEMO_FAX_TO")}, {"fax_from_name", Environment.GetEnvironmentVariable ("RC_DEMO_FAX_FROM_NAME")}, {"fax_from_phone", Environment.GetEnvironmentVariable ("RC_DEMO_FAX_FROM")}, {"fax_from_fax", Environment.GetEnvironmentVariable ("RC_DEMO_FAX_FROM")}, {"fax_coverpage_text", Environment.GetEnvironmentVariable ("RC_DEMO_FAX_COVERPAGE_TEXT")} }; string html = template(data); byte[] coverPageBytes = Encoding.ASCII.GetBytes(html); var coverPage = new Attachment ("cover.htm", "text/html", coverPageBytes); return coverPage; }
public void SendFax() { const string text = "Hello world!"; var json = "{\"to\":[{\"phoneNumber\":\"258369741\"}],\"faxResolution\":\"High\"}"; var byteArrayText = Encoding.UTF8.GetBytes(text); var attachment = new Attachment("test.txt", "application/octet-stream", byteArrayText); var attachment2 = new Attachment("test2.txt", "text/plain", byteArrayText); var attachments = new List<Attachment> { attachment, attachment2 }; Request request = new Request(FaxEndPoint, json, attachments); ApiResponse response = sdk.Platform.Post(request); JToken token = response.Json; var availability = (string)token.SelectToken("availability"); Assert.AreEqual("Alive", availability); }