ActionConverter.cs
1 using System;
2 using System.Linq;
4 using Newtonsoft.Json.Linq;
5 
6 namespace Microsoft.Bot.Builder.Calling.ObjectModel.Contracts
7 {
12  public class ActionConverter : JsonCreationConverter<ActionBase>
13  {
14  protected override ActionBase Create(Type objectType, JObject jsonObject)
15  {
16  var actionProperties = jsonObject.Properties().Where(p => p != null && p.Name != null && String.Equals(p.Name, "action", StringComparison.OrdinalIgnoreCase));
17  string type = null;
18 
19  if (actionProperties.Count() == 1)
20  {
21  type = (string)actionProperties.First();
22  }
23  else
24  {
25  throw new ArgumentException(String.Format("Expected single action."));
26  }
27 
28  if (String.Equals(type, ValidActions.AnswerAction, StringComparison.OrdinalIgnoreCase))
29  {
30  return new Answer();
31  }
32  else if (String.Equals(type, ValidActions.HangupAction, StringComparison.OrdinalIgnoreCase))
33  {
34  return new Hangup();
35  }
36  else if (String.Equals(type, ValidActions.RejectAction, StringComparison.OrdinalIgnoreCase))
37  {
38  return new Reject();
39  }
40  else if (String.Equals(type, ValidActions.PlayPromptAction, StringComparison.OrdinalIgnoreCase))
41  {
42  return new PlayPrompt();
43  }
44  else if (String.Equals(type, ValidActions.RecordAction, StringComparison.OrdinalIgnoreCase))
45  {
46  return new Record();
47  }
48  else if (String.Equals(type, ValidActions.RecognizeAction, StringComparison.OrdinalIgnoreCase))
49  {
50  return new Recognize();
51  }
52 
53  throw new ArgumentException(String.Format("The given action '{0}' is not supported!", type));
54  }
55  }
56 }
This is the action which customers can specify to indicate that the server call agent should accept t...
Definition: Answer.cs:13
Helper class to use for deserializing where the concrete classes are determined by checking propertie...
Root namespace for the Microsoft Bot Builder Calling SDK object model.
This is a helper class for validating actions specified by customers
Definition: ValidActions.cs:11
This is the action which customers can specify to indicate that the server call agent should perform ...
This is the action which customers can specify to indicate that the server call agent should play/tts...
Definition: PlayPrompt.cs:10
override ActionBase Create(Type objectType, JObject jsonObject)
Create an instance of objectType, based properties in the JSON object
By default Json.net doesn&#39;t know how to deserialize JSON data into Interfaces or abstract classes...
Root namespace for the Microsoft Bot Builder Calling SDK.
This is the action which customers can specify to indicate that the server call agent should reject t...
Definition: Reject.cs:9
This is the action which customers can specify to indicate that the server call agent should start re...
Definition: Record.cs:11
This is the action which customers can specify to indicate that the server call agent should hangup t...
Definition: Hangup.cs:9
Namespace for utilities and helpers in the Microsoft Bot Builder Calling SDK.
Root namespace for the Microsoft Bot Builder SDK.