This framework is useful for creating simple whatsapp chatbots with multiple services.
- Configure the bot by adding credentials in
config.gounderconfigpackage - Add required services
- Add the newly created to registry
Follow the Meta Documentations to get your credentials
- Creat a package under
servicesfolder - Declare a package varialbe
Serviceof any type - Implement
Serviceinterface forServiceObjecttype Service interface { Execute (*Prompt) *Result Help() *Result }Service,ResultandPrompttypes are defined underapipackage - Import your package and add to registry map in
registry.gounder `servicemanager`` package
package newservice
import "whatsup/api"
type service struct{}
var Service service
func (service) Execute(prompt *api.Prompt) *api.Result {
text := api.NewTextPayload("Hey There")
return api.NewResult("text", text)
}
func (service) Help() *api.Result {
text := api.NewTextPayload("Okay I can help!")
return api.NewResult("text", text)
}
- When a message is send with a prefix, the service is extracted from it
- Then the service registry is looked up to check whether the service exists
- If the service exists then it is executed and the result from the service is sent back to the user