Listen for Messages
Subscribed users, bots, and globals broadcast received and sent messages to the plugin.
These can be listened for by binding functions to OnMessageReceived
and
OnMessageSent
:
client.OnMessageReceived += (Message message) => {
string body = message.Body;
string context = message.ParseContext<string>().Data;
}
client.OnMessageSent += (Message message) => {
string body = message.Body;
string context = message.ParseContext<string>().Data;
}
Get Recent Messages
User
var result = await client.User.GetMessages("5db0acbc46d06a0089c1f06b", limit: 100, page: 1);
if (result.IsSuccess) {
Message[] messages = result.Data;
}
Bot
var result = await client.Bot.GetMessages("5db0acbc46d06a0089c1f06b", limit: 100, page: 1);
if (result.IsSuccess) {
Message[] messages = result.Data;
}
Get Conversation
User
var result = await client.User.GetMessagesWithBot(userId: "5db0acbc46d06a0089c1f06b", botId: "5db0acbc46d06a0089c1f06b", limit: 100, page: 1);
if (result.IsSuccess) {
Message[] messages = result.Data;
}
Bot
var result = await client.Bot.GetMessagesWithUser(botId: "5db0acbc46d06a0089c1f06b", userId: "5db0acbc46d06a0089c1f06b", limit: 100, page: 1);
if (result.IsSuccess) {
Message[] messages = result.Data;
}
Send Message
User
Send a message from a user to a bot:
var result = await client.User.SendMessage(userId: "5db0acbc46d06a0089c1f06b", botId: "5db0acbc46d06a0089c1f06b", "test message", new {context = 5});
Bot
Send a message from a bot to a user:
var result = await client.Bot.SendMessage(botId: "5db0acbc46d06a0089c1f06b", userId: "5db0acbc46d06a0089c1f06b", "test message", new {context = 5});
Get Threads
User
var result = await client.User.GetThreads("5db0acbc46d06a0089c1f06b", limit: 100, page: 1);
Bot
var result = await client.Bot.GetThreads("5db0acbc46d06a0089c1f06b", limit: 100, page: 1);