Skip to content

Commit 60022b6

Browse files
committed
feat(AssistantV2): Added converter to MessageInputOptions
1 parent 95989e2 commit 60022b6

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

Scripts/Services/Assistant/v2/Models/MessageInputOptions.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
*/
1717

1818
using FullSerializer;
19+
using System;
20+
using System.Collections.Generic;
1921

2022
namespace IBM.WatsonDeveloperCloud.Assistant.v2
2123
{
2224
/// <summary>
2325
/// Optional properties that control how the assistant responds.
2426
/// </summary>
25-
[fsObject]
27+
[fsObject(Converter = typeof(MessageInputOptionsConverter))]
2628
public class MessageInputOptions
2729
{
2830
/// <summary>
@@ -50,4 +52,58 @@ public class MessageInputOptions
5052
public bool? ReturnContext { get; set; }
5153
}
5254

55+
#region Create Value Converter
56+
public class MessageInputOptionsConverter : fsConverter
57+
{
58+
private fsSerializer _serializer = new fsSerializer();
59+
60+
public override bool CanProcess(Type type)
61+
{
62+
return type == typeof(MessageInputOptions);
63+
}
64+
65+
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
66+
{
67+
throw new NotImplementedException();
68+
}
69+
70+
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
71+
{
72+
MessageInputOptions messageInputOptions = (MessageInputOptions)instance;
73+
serialized = null;
74+
75+
Dictionary<string, fsData> serialization = new Dictionary<string, fsData>();
76+
77+
fsData tempData = null;
78+
79+
if (messageInputOptions.Debug != null)
80+
{
81+
_serializer.TrySerialize(messageInputOptions.Debug, out tempData);
82+
serialization.Add("debug", tempData);
83+
}
84+
85+
if (messageInputOptions.Restart != null)
86+
{
87+
_serializer.TrySerialize(messageInputOptions.Restart, out tempData);
88+
serialization.Add("restart", tempData);
89+
}
90+
91+
if (messageInputOptions.AlternateIntents != null)
92+
{
93+
_serializer.TrySerialize(messageInputOptions.AlternateIntents, out tempData);
94+
serialization.Add("alternate_intents", tempData);
95+
}
96+
97+
if (messageInputOptions.ReturnContext != null)
98+
{
99+
_serializer.TrySerialize(messageInputOptions.ReturnContext, out tempData);
100+
serialization.Add("return_context", tempData);
101+
}
102+
103+
serialized = new fsData(serialization);
104+
105+
return fsResult.Success;
106+
}
107+
#endregion
108+
}
53109
}

0 commit comments

Comments
 (0)