Class Connector
The class Connector
allows communication with the Cluster API server by retrieving and sending questions and answers.
Inheritance
Inherited Members
Namespace: ClusterClient
Assembly: ClusterClient.dll
Syntax
public class Connector
Constructors
| Improve this Doc View SourceConnector(String, String, Int32)
Initializes a new connector instance with the given websocket host URI used for its websocket connection and the given timeout set as the timeout before giving up on trying to connect to the server.
Declaration
public Connector(string authorization, string webSocketHostURI = "wss://clusterapi20200320113808.azurewebsites.net/api/Chatbot/WS", int webSocketConnectionTimeout = 10)
Parameters
Type | Name | Description |
---|---|---|
System.String | authorization | The value to be set for the Authorization header in the initial web socket connection request. |
System.String | webSocketHostURI | The URI referencing the server address to which a websocket connection should be made. |
System.Int32 | webSocketConnectionTimeout | The timeout to be set in seconds for the websocket connection before giving up. By default set to 10 seconds. |
Properties
| Improve this Doc View SourceEndPointAddress
The end point uri to which proactive messages should be sent.
Declaration
public string EndPointAddress { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceAnswerQuestion(String, UserAnswer)
Sends an answer
provided by a user identified by the given userID
.
Declaration
public void AnswerQuestion(string userID, UserAnswer answer)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user ID identifying the user who submitted the answer. |
UserAnswer | answer | The answer to be sent. |
Exceptions
Type | Condition |
---|---|
System.Exception | An exception has been passed by the web socket thread. |
AnswerQuestion(String, Int32, String)
Sends an answer
provided by a user identified by the given userID
to a question identified by
the given questionID
.
Declaration
public void AnswerQuestion(string userID, int questionID, string answer)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user ID identifying the user who submitted the answer. |
System.Int32 | questionID | The question ID identifying the question for which an |
System.String | answer | An answer to the question identified by the given |
Exceptions
Type | Condition |
---|---|
System.Exception | An exception has been passed by the web socket thread. |
AnswerQuestions(String, ICollection<UserAnswer>)
Processes a series of questionID-answer pairs from a user identified by the given userID
.
Declaration
public void AnswerQuestions(string userID, ICollection<UserAnswer> userAnswers)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user id of the user who wants to send answers to questions. |
System.Collections.Generic.ICollection<UserAnswer> | userAnswers |
Exceptions
Type | Condition |
---|---|
System.Exception | An exception has been passed by the web socket thread. |
BlockProactiveMessagingForUser(String)
Disables proactive messaging for a user.
Declaration
public void BlockProactiveMessagingForUser(string userID)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user id of the user for whom proactive messaging should be disabled. |
CloseWebSocketConnection()
Sends a stop signal to the thread running the websocket connection of this connector to close the connection and stop the thread.
Declaration
public void CloseWebSocketConnection()
EnableWebSocketStateCheck(Boolean)
Enables a constant check of the websocket state on the debugging output stream. Not that this is a very CPU consuming option.
Declaration
public void EnableWebSocketStateCheck(bool flag)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | flag |
GetNewAnswersForUser(String)
Returns all answers received from the server and addressed to the user identified by the given userID
.
This method is not idempotent, which means that calling it twice does not necessarily return the same result twice.
Declaration
public ISet<ServerAnswer> GetNewAnswersForUser(string userID)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user ID of the user who wants to receive answers to previously asked questions. |
Returns
Type | Description |
---|---|
System.Collections.Generic.ISet<ServerAnswer> | A set containing all answers received from the server and addressed to the user identified by the given |
GetNewResponses()
Returns all answers received from the server.
Declaration
public ISet<ServerAnswer> GetNewResponses()
Returns
Type | Description |
---|---|
System.Collections.Generic.ISet<ServerAnswer> | A set containing all answers received from the serverin response to questions from this client. |
HasAnswerToQuestionOfUser(Int32, String)
Checks whether the server has an answer to the question of the given user, identified by its questionID
and userID
.
Declaration
public bool HasAnswerToQuestionOfUser(int questionID, string userID)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | questionID | The question ID of the question for which is checked whether an answer is available. |
System.String | userID | The user ID of the user for whom it is checked whether an answer is available. |
Returns
Type | Description |
---|---|
System.Boolean | True if and only if there is a server answer for the user identified with the given |
MissedProactiveMessagesForUser(String)
Checks whether proactive messages couldn't be sent to a user because they were blocked.
Declaration
public bool MissedProactiveMessagesForUser(string userID)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user id of the user for whom should be checked whether proactive messages have been missed. |
Returns
Type | Description |
---|---|
System.Boolean |
ProactiveMessagingBlockedForUser(String)
Checks whether proactive messaging is currently enabled for a user.
Declaration
public bool ProactiveMessagingBlockedForUser(string userID)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user id of the user for whom the proactive messaging blocking state should be checked. |
Returns
Type | Description |
---|---|
System.Boolean | True if and only if proactive messaging is blocked for the given user or if the |
RequestAndRetrieveUnansweredQuestions(String, Double)
Creates a request to the server to receive unanswered questions for a user. This method is CPU-bound (use Task.Run to call from a UI thread).
Declaration
public ISet<ServerQuestion> RequestAndRetrieveUnansweredQuestions(string userID, double timeout = 5)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user ID of the user who should answer the questions. |
System.Double | timeout |
Returns
Type | Description |
---|---|
System.Collections.Generic.ISet<ServerQuestion> | A set of server questions. If the set is empty, no questions are available. |
Exceptions
Type | Condition |
---|---|
System.Exception | The websocket thread has passed an exception. The passed exception is thrown by this method. |
ResetConnection()
Resets the websocket thread by stopping the current thread and starting a new one.
Post | If a websocket thread was running, it is stopped and replaced by a new websocket thread running a new connection. If no websocket thread was running, a new one is initialized running a connection. |
Declaration
public void ResetConnection()
SendFeedbackOnAnswer(String, Int32, Int32, Int32)
Processes a feedback response from a user identified by the given userID
concerning
the question-answer pair identified by questionID
and answerID
.
Declaration
public void SendFeedbackOnAnswer(string userID, int answerID, int questionID, int feedback)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user id of the user who wants to send feedback. |
System.Int32 | answerID | The answer ID related to the question-answer pair for which feedback is sent. |
System.Int32 | questionID | The question ID related to the question-answer pair for which feedback is sent. |
System.Int32 | feedback | A feedback code related to the feedback. This could be as simple as 'good' = 1 and 'bad' = 0, or more advanced using feelings like 'happy' = 0, 'angry' = 1, 'sad' = 2 ... as long as the server understands it well. |
Exceptions
Type | Condition |
---|---|
System.Exception | An exception has been passed by the web socket thread. |
SendMessageToEndPointAsync(String, String)
Sends a json string to the end point of this connector.
Declaration
public Task<bool> SendMessageToEndPointAsync(string content, string route = "no_action")
Parameters
Type | Name | Description |
---|---|---|
System.String | content | The json string to be sent. |
System.String | route |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | True if and only if the end point address of this connector is set and the response code is 2xx. |
SendQuestionAndWaitForAnswer(String, String, Double)
Sends a given question from a given user to the server and returns the answer from the server.
Declaration
public ServerAnswer SendQuestionAndWaitForAnswer(string userID, string question, double timeout = 5)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The ID of the user for whom an answer is required. |
System.String | question | The question to which an answer is required. |
System.Double | timeout | The timeout to be set in seconds before throwing an exception. |
Returns
Type | Description |
---|---|
ServerAnswer | A server answer object with a question ID assigned to the given question by the server.
In case the |
Exceptions
Type | Condition |
---|---|
System.Exception | The websocket thread has passed an exception. The passed exception is thrown by this method. |
StoreMessageFromServerAsync(String)
Parses and stores a message received from the server, so it can be retrieved by another method later on.
Declaration
public Task StoreMessageFromServerAsync(string serverMessage)
Parameters
Type | Name | Description |
---|---|---|
System.String | serverMessage | A message from the server that should be stored. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
SurpressConnectionErrors()
Makes the public methods of this connector surpress connection related errors.
Declaration
public void SurpressConnectionErrors()
UnblockProactiveMessagingForUser(String)
Enables proactive messaging for a user.
Proactive messaging is enabled by default if the EndPointAddress
of this connector is set.
Declaration
public void UnblockProactiveMessagingForUser(string userID)
Parameters
Type | Name | Description |
---|---|---|
System.String | userID | The user id of the user for whom proactive messaging should be enabled. |