Class RocketChatService
A client for accessing the Rocket.Chat API
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 async 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 async 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 async 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)
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 async 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 |
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 async 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 |
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 async 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(RocketChatService.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 async 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 async 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 async 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 async 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 |