Class RocketChatService
A client for accessing the Rocket.Chat API
Inheritance
Namespace: i5.Toolkit.Core.RocketChatClient
Assembly: cs.temp.dll.dll
Syntax
public class RocketChatService : IService
Constructors
RocketChatService(string)
Creates a new Rocket.Chat client instance
Declaration
public RocketChatService(string hostAddress)
Parameters
Type | Name | Description |
---|---|---|
string | hostAddress | The URL address where the Rocket.Chat server is hosted |
Properties
AuthToken
AuthToken (X-Auth-Token) of the user. It is automatically set during the login.
Declaration
public string AuthToken { get; }
Property Value
Type | Description |
---|---|
string |
HostAddress
The address where the Rocket.Chat server is hosted
Declaration
public string HostAddress { get; set; }
Property Value
Type | Description |
---|---|
string |
JsonSerializer
Module for serializing and de-serializing JSON files Initialized by default with the JsonUtilityAdapter
Declaration
public IJsonSerializer JsonSerializer { get; set; }
Property Value
Type | Description |
---|---|
IJsonSerializer |
UserID
UserID (X-User-Id) of the user. It is automatically set during the login.
Declaration
public string UserID { get; }
Property Value
Type | Description |
---|---|
string |
Methods
Cleanup()
Cleans up the service as it is deregistered from the service manager
Declaration
public void Cleanup()
GetChannelListJoinedAsync()
Get the user's channel list of joined channels. Requires login first. Note that this only includes public channels. For private channels, get the user's groups. See https://developer.rocket.chat/reference/api/rest-api/endpoints/team-collaboration-endpoints/channels-endpoints/list
Declaration
public Task<WebResponse<ChannelGroup[]>> GetChannelListJoinedAsync()
Returns
Type | Description |
---|---|
Task<><WebResponse<ChannelGroup[]>> | Retunrs a WebResponse with the server's answer and an array of the user's channels |
GetGroupListAsync()
Gets the user's list of joined groups. Requires login first. This does not only include groups but also private channels. See https://developer.rocket.chat/reference/api/rest-api/endpoints/team-collaboration-endpoints/groups-endpoints/list
Declaration
public Task<WebResponse<ChannelGroup[]>> GetGroupListAsync()
Returns
Type | Description |
---|---|
Task<><WebResponse<ChannelGroup[]>> | Returns a WebResponse of the server and an array of the user's groups |
GetMeAsync()
Get the profile information of the logged-in user. Requires login first. See https://developer.rocket.chat/reference/api/rest-api/endpoints/other-important-endpoints/authentication-endpoints/me
Declaration
public Task<WebResponse<UserInfo>> GetMeAsync()
Returns
Type | Description |
---|---|
Task<><WebResponse<UserInfo>> |
Initialize(IServiceManager)
Initializes the service as it gets registerd with a ServiceManager
Declaration
public void Initialize(IServiceManager owner)
Parameters
Type | Name | Description |
---|---|---|
IServiceManager | owner | The service manager which now owns this service |
LoginAsync(string, string)
Log in to the server with a username and password. It sets the AuthToken and UserID properties. See https://developer.rocket.chat/reference/api/rest-api/endpoints/other-important-endpoints/authentication-endpoints/login
Declaration
public Task<WebResponse<LoginResponse>> LoginAsync(string username, string password)
Parameters
Type | Name | Description |
---|---|---|
string | username | The username of the user who wants to log in |
string | password | The password of the user who wants to log in |
Returns
Type | Description |
---|---|
Task<><WebResponse<LoginResponse>> | Returns the parsed login response |
LoginAsync(string)
Log in to the server with an auth token. It sets the AuthToken and UserID properties. See https://developer.rocket.chat/reference/api/rest-api/endpoints/other-important-endpoints/authentication-endpoints/login
Declaration
public Task<WebResponse<LoginResponse>> LoginAsync(string authToken)
Parameters
Type | Name | Description |
---|---|---|
string | authToken | The auth token that identifies and authorized the user who wants to log in |
Returns
Type | Description |
---|---|
Task<><WebResponse<LoginResponse>> | Returns true if the login was successful, otherwise false |
PostMessageAsync(string, string)
Post a message to a given room (channel, team, direct message etc.) of the user. Requires login first. See https://developer.rocket.chat/reference/api/rest-api/endpoints/team-collaboration-endpoints/chat-endpoints/postmessage
Declaration
public Task<WebResponse<MessageSentResponse>> PostMessageAsync(string targetID, string text = "")
Parameters
Type | Name | Description |
---|---|---|
string | targetID | rid of the room, channel name (#) or user name (@) |
string | text |
Returns
Type | Description |
---|---|
Task<><WebResponse<MessageSentResponse>> | Returns true if the message was successfully sent |
SendHttpRequestAsync(RequestType, string, string)
Send an arbitrary HTTP request to the host. Supports only GET and POST with application/json header. APIs See https://developer.rocket.chat/reference/api/rest-api
Declaration
public Task<WebResponse<string>> SendHttpRequestAsync(RocketChatService.RequestType type, string apiSuffix, string payload = "")
Parameters
Type | Name | Description |
---|---|---|
RocketChatService.RequestType | type | request type, supports GET and POST |
string | apiSuffix | the api string behind the host, e.g. /api/v1/login |
string | payload | Payload of a POST request, optional. |
Returns
Type | Description |
---|---|
Task<><WebResponse<string>> | WebResponse with the server's answer |
SendWebSocketRequestAsync(string, string)
Send an arbitrary WebSocket request to the host. APIs See https://developer.rocket.chat/reference/api/realtime-api
Declaration
public Task<WebResponse<string>> SendWebSocketRequestAsync(string uniqueID, string message)
Parameters
Type | Name | Description |
---|---|---|
string | uniqueID | id of the request |
string | message | message to send |
Returns
Type | Description |
---|---|
Task<><WebResponse<string>> | Returns the API's answer as a WebResponse object |
SubscribeRoomMessageAsync(string, string)
Start listening for messages in a particular channel Starts a web socket that keeps up a connection to the API. See https://developer.rocket.chat/reference/api/realtime-api/subscriptions/stream-room-messages
Declaration
public Task SubscribeRoomMessageAsync(string roomID, string uniqueID)
Parameters
Type | Name | Description |
---|---|---|
string | roomID | rid of the room (must be the internal id, the human-readable name starting with the '#' does not work) |
string | uniqueID | a unique ID of this subscription (can be chosen arbitrarily) |
Returns
Type | Description |
---|---|
Task |
UnsubscribeRoomMessageAsync(string)
Stop listening for messages in a room, given the ID of the former subscription. Closes this particular Web socket connection to the API
Declaration
public Task UnsubscribeRoomMessageAsync(string uniqueID)
Parameters
Type | Name | Description |
---|---|---|
string | uniqueID | The subscribtion ID that identifies the subscription |
Returns
Type | Description |
---|---|
Task |
Events
OnMessageReceived
Fired when the client receives a WebSocket message from a room.
Declaration
public event RocketChatService.ReceivedMessageHandler OnMessageReceived
Event Type
Type | Description |
---|---|
RocketChatService.ReceivedMessageHandler |