Giter Site home page Giter Site logo

pfbot's Introduction

Plus Friend Bot SDK for Go

pfbot is the unofficial (Kakao Talk) Plus Friend Bot SDK for the Go programming language.

bot := pfbot.NewBot()

bot.HandleKeyboard(func() *pfbot.Keyboard {
	return &pfbot.Keyboard{
		Type: "text",
		Buttons: []string{
			"Hello",
			"World",
		},
	}
})

bot.Run(":8080")
$ curl -X GET http://127.0.0.1:8080/keyboard

Installation

If you are using Go 1.6 and higher you can use the following command to retrieve the SDK.

Installation is done using the go get command:

$ go get -u github.com/loslch/pfbot

Quick Start

To build and run your Plus Friend Bot, you should create Bot instance and implement handlers which you want.

Create Bot instance:

bot := pfbot.NewBot()

Run your bot:

bot.Run(":8080")

Implement Keyboard handler and bind:

func keyboardHandler() *pfbot.Keyboard {
  return &pfbot.Keyboard{
    Type: "text",
    Buttons: []string{
      "Hello",
      "World",
    },
  }
}

bot.HandleKeyboard(keyboardHandler)

Implement Message handler and bind:

func messageHandler(userKey, messageType, content string) (*pfbot.Message, *pfbot.Keyboard) {
  //do something

  msg := &pfbot.Message{
    Text: "hello world",
  }
  keyboard := &pfbot.Keyboard{
    Type: "text",
  }
  return msg, keyboard
}

bot.HandleMessage(messageHandler)

Implement AddFriend handler and bind:

func addFriendHandler(userKey string) *pfbot.Status {
  return &pfbot.Status{200, 0, "success"}
}

bot.HandleAddFriend(addFriendHandler)

Implement BlockFriend handler and bind:

func blockFriendHandler(userKey string) *pfbot.Status {
  return &pfbot.Status{200, 0, "success"}
}

bot.HandleBlockFriend(blockFriendHandler)

Implement QuitChatRoom handler and bind:

func quitChatRoom(userKey string) *pfbot.Status {
  return &pfbot.Status{200, 0, "success"}
}

bot.HandleQuitChatRoom(quitChatRoom)

To run bot server:

bot.Run("/", ":8080")

or to run with net/http:

http.ListenAndServe(":8080", bot)

Configure AppKey and AppSecret (but, no use case yet):

bot.AppKey = "key"
bot.AppSecret = "secret"

Links

License

This project is distributed under the MIT License, see LICENSE.txt for more information.

pfbot's People

Contributors

loslch avatar

Watchers

 avatar  avatar

pfbot's Issues

support TLS(HTTPS)

implement method bot.RunTLS("/", ":8080", ...certificates) for supporting TLS bot.

set prefix

Currently, setting prefix is not working properly.

If the user set prefix and run server like this bot.Run("/api", ":8080"), it should server at http://127.0.0.1:8080/api/keyboard.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.