Bot usage

On this page, you will get a short instruction, how to create a bot using the GroupMe SDK.

Prerequisites

To use the BotFactory, you have to instantiate a CkSoftware.GroupMe.Sdk.Core.WebApiAccess class using the API base url and a accessToken as described here: WebApiAccess

Create a bot

First, you need to instantiate a CkSoftware.GroupMe.Sdk.Bot.GroupMeBotFactory using the IWebApiAccess from the prerequisites:

var botFactory = new GroupMeBotFactory(_webApiAccess);

using this bot factory class, you can create a new bot or get all available bots. We want to create a bot, so we use the method CreateBot(string name, string groupId):

var bot = botFactory.CreateBot("MySuperBot", "1234567");

When we got the bot, we can fluently configure an avatar image and a callback url and can start the bot synchronous or asynchronous:

var startedBot = await bot.WithAvatar("https://i.groupme.com/xxyyzz") // NEEDS to be a image, processed by the GroupMe imaging service!
    .WithCallback("http://yourdomain.com/botcallback")
    .StartBotAsync();

Voila, the bot is up and running and you can write messages to a group:

await startedBot.SendMessage("Hello World").SubmitAsync();

Full code

Here is the code from above in one piece, just for reference and easier copy-paste :)

var botFactory = new GroupMeBotFactory(_webApiAccess);
var bot = botFactory.CreateBot("MySuperBot", "1234567");

var startedBot = await bot.WithAvatar("https://i.groupme.com/xxyyzz") // NEEDS to be a image, processed by the GroupMe imaging service!
    .WithCallback("http://yourdomain.com/botcallback")
    .StartBotAsync();

await startedBot.SendMessage("Hello World").SubmitAsync();

Last edited Jan 11, 2014 at 11:00 AM by Stops, version 2