diff --git a/LiveChatApi/LiveChatApi/Field.cs b/LiveChatApi/LiveChatApi/Field.cs
new file mode 100644
index 0000000..e2843e0
--- /dev/null
+++ b/LiveChatApi/LiveChatApi/Field.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LiveChatApi
+{
+ public class Field
+ {
+ public string Name { get; set; }
+
+ public string Value { get; set; }
+
+ public string Url { get; set; }
+ }
+}
diff --git a/LiveChatApi/LiveChatApi/LiveChatApi.csproj b/LiveChatApi/LiveChatApi/LiveChatApi.csproj
index 2bee7a6..3f8735a 100644
--- a/LiveChatApi/LiveChatApi/LiveChatApi.csproj
+++ b/LiveChatApi/LiveChatApi/LiveChatApi.csproj
@@ -52,6 +52,7 @@
+
diff --git a/LiveChatApi/LiveChatApi/Visitors.cs b/LiveChatApi/LiveChatApi/Visitors.cs
index 63b3828..e21a3f9 100644
--- a/LiveChatApi/LiveChatApi/Visitors.cs
+++ b/LiveChatApi/LiveChatApi/Visitors.cs
@@ -39,16 +39,24 @@ public async Task List(Dictionary parameters = null)
return await Api.Get(uri);
}
- public async Task AddCustomDetails(string visitorID, string licenseID, string token, string id, Dictionary fields, string icon = "")
+ public async Task AddCustomDetails(string visitorID, string licenseID, string token, string id, IEnumerable fields, string icon = "")
{
string uri = string.Format("visitors/{0}/details", HttpUtility.UrlEncode(visitorID));
string content = string.Format("license_id={0}&token={1}&id={2}", HttpUtility.UrlEncode(licenseID), HttpUtility.UrlEncode(token), HttpUtility.UrlEncode(id));
- if (fields != null && fields.Count > 0)
+ if (fields != null && fields.Count() > 0)
{
int i = 0;
- foreach (var keyValuePair in fields)
+ foreach (var field in fields)
{
- content += string.Format("&fields[{0}][name]={1}&fields[{0}][value]={2}", i, HttpUtility.UrlEncode(keyValuePair.Key), HttpUtility.UrlEncode(keyValuePair.Value));
+ string encodedName = HttpUtility.UrlEncode(field.Name);
+ string encodedValue = HttpUtility.UrlEncode(field.Value);
+ string encodedUrl = HttpUtility.UrlEncode(field.Url);
+
+ if (String.IsNullOrWhiteSpace(field.Url))
+ content += string.Format("&fields[{0}][name]={1}&fields[{0}][value]={2}", i, encodedName, encodedValue);
+ else
+ content += string.Format("&fields[{0}][name]={1}&fields[{0}][value]={2}&fields[{0}][url]={3}", i, encodedName, encodedValue, encodedUrl);
+
i++;
}
}
diff --git a/LiveChatApi/LiveChatApiExample/ApiExample.cs b/LiveChatApi/LiveChatApiExample/ApiExample.cs
index 3381204..064d761 100644
--- a/LiveChatApi/LiveChatApiExample/ApiExample.cs
+++ b/LiveChatApi/LiveChatApiExample/ApiExample.cs
@@ -1,4 +1,5 @@
-using System;
+using LiveChatApi;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -599,8 +600,8 @@ public async Task VisitorsTest()
string licenseID = "123456";
string token = "bad02a95a61a44bd466b9cdd262ac6a0";
string id = "my-app";
- Dictionary fields = new Dictionary();
- fields.Add("name1", "value1");
+ List fields = new List();
+ fields.Add( new Field { Name = "name1", Value = "value1" });
result = await Api.Visitors.AddCustomDetails(visitorID, licenseID, token, id, fields);
Console.WriteLine(result);