Skip to content

Golang implementation of a bare bones groupme bot that can be easily extended.

License

Notifications You must be signed in to change notification settings

tipsysquid/groupmebot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GroupMeBot Framework

This is a GroupMe Bot Framework that does the basics for you. The bot is configured using the developer API information. Once that file is created, the bot is able to start and respond to incoming messages, assuming your ports are open and your bot is registered to your IP address. To add functionality, simply add functions that generate the appropriate repsonses and create a hook with whatever trigger you'd like!

Setup

Installing Go

This project uses the programming language Go. Make sure you install it and set your GOPATH environment variable to the location of the directory that you are working.

Creating your first bot

  1. To create the bot first make your folders.
mkdir -p $GOPATH/src/github.com/user/mybot
cd $GOPATH/src/github.com/user/mybot
  1. Create your mybot_cfg.json file shown above with your credentials inserted for that bot_id and group_id 1. Create a bot on the GroupMe Website. 2. Make sure and take note of your bot_id and group_id. 3. Create a mybot_cfg.json file.
{
  "bot_id": "your_bot_id",
  "group_id": "your_group_id",
  "host": "0.0.0.0",
  "port": "8080",
  "logfile": "messages.csv"
}

Make sure that the bot you created on the GroupMe Website is registerd to your External IP and port. Also make sure that whichever port you use, is open on your host.

  1. Copy/Create a main file similar to the one in this repositories example folder
cp $GOPATH/src/github.com/adammohammed/examples/main.go .
  1. Run this command while in the directory where your main file is located
go get -u -v github.com/adammohammed/groupmebot
go install
  1. Finally you can run your bot using the go run main.go command

Creating plugins

Defining hooks is simple. The hooks signature needs to be as follows:

func my_hook(msg groupmebot.InboundMessage) (string) {
        resp := fmt.Sprintf("Hi there, %v.", msg.Name)
        return resp
}

This function must accept only an Inbound message as input. The output must be a string. The actual body of the fuction can do whatever you please but the signature is vital to be able to add it to the list of hooks.

Adding items to the hooks is done as shown below. Assume that these are function names for functions defined with the signature we defined earlier.

bot.AddHook("Hi!$", my_hook)

The first parameter to the AddHook method is the regular expression trigger that the message text must match. In this example, if the message text ends with "Hi!", the bot will send a response. If the bot finds the incoming message matches the trigger expression, the function is executed. When a message is received by the bot, it checks to see if the text matches any available hooks added by the AddHooks method.

Future changes

  • Make it possible to dynamically populate hooks from plugin directory.
  • Allow hooks to be removed/updated

License

Copyright (c) 2017 Adam Mohammed

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Golang implementation of a bare bones groupme bot that can be easily extended.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%