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
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
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"
This project is distributed under the MIT License, see LICENSE.txt for more information.