Skip to content

A Java framework for building bots on Kik Messenger Platform

License

Notifications You must be signed in to change notification settings

gitter-badger/kik-botmill

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Maven Central Javadocs

Kik-BotMill - Tools to Mill Kik Bots

Inspired by our first ever Bot Framework FB-BotMill

Kik-BotMill is designed to ease the process of developing, designing and running bots that exist inside Kik Messenger.

It provides a semantic Java API that can be imported on your Java EE Project to send and receive messages from Kik so that developers can focus on developing the actual application instead of dealing with Kik API endpoints.

Getting Started

x.x.x - indicates version.

<dependency>
  <groupId>co.aurasphere.botmill</groupId>
  <artifactId>kik-botmill</artifactId>
  <version>x.x.x</version>
</dependency>

Gradle

compile 'co.aurasphere.botmill:kik-botmill:x.x.x'

Grovvy

@Grapes( 
    @Grab(group='co.aurasphere.botmill', module='kik-botmill', version='x.x.x') 
)

Other ways to import, visit Maven central repo site

Once you've imported the API. You need to register the KikBotMillServlet. To do that, create a Servlet project in your IDE and add this to your web.xml:

 <servlet>
	  <servlet-name>myKikBot</servlet-name>
	  <servlet-class>co.aurasphere.botmill.kik.KikBotMillServlet</servlet-class>
	  <init-param>
		  <param-name>bot-definition-class</param-name>
		  <param-value>com.sample.kik.demo.KikBotEntryPoint</param-value>
	  </init-param>
	  <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
	  <servlet-name>myKikBot</servlet-name>
	  <url-pattern>/myKikBot</url-pattern>
  </servlet-mapping>
  

Your KikBotEntryPoint should extends KikBotMillEntry. You need to override the kikBotEntry and define your domains and behaviours.

public class KikBotEntryPoint extends KikBotMillEntry {
	/**
	 * Entry point is the main method that will be called only once.
	 * This is where we define our configuration and responses.
	 */
	@Override
	protected void kikBotEntry() {
		
		//	setup
		KikBotMillContext.getInstance().setup("<USERNAME>", "<APIKEY>");
		
		//	configuration.
		ConfigurationBuilder.getInstance().setWebhook("<webhook>/myKikBot")
			.setManuallySendReadReceipts(false)
			.setReceiveDeliveryReceipts(false)
			.setReceiveIsTyping(true)
			.setReceiveReadReceipts(false)
			.setStaticKeyboard(
				KeyboardBuilder.getInstance().setType(KeyboardType.SUGGESTED)
				.addResponse(MessageFactory.createResponse("Make me a ChatBot!", ResponseType.TEXT))
				.addResponse(MessageFactory.createResponse("What are ChatBots?", ResponseType.TEXT))
				.addResponse(MessageFactory.createResponse("Milling Tools!", ResponseType.TEXT))
			.buildKeyboard())
		.buildConfiguration();
			
		//	Domain > collection of responses
		KikBotMillContext.getInstance().registerDomain(new SampleDomain());
		
	}
}

Your domain holds all the actions of your Bot.
In the following example, the action will catch either a "hello" or "HELLO" response from the user and respond back a message "Hey ! How can I help you today?".

public class SampleDomain extends AbstractDomain {

	@Override
	public void buildDomain() {
	
		ActionFrameBuilder.getInstance()
			.setEvent(EventFactory .textMessagePattern("(?i:hello)"))
			.addReply(new TextMessageReply() {
				@Override
				public TextMessage processReply(Message message) {
					return TextMessageBuilder.getInstance()
							.setBody("Hey " + ((IncomingMessage) message).getFrom() + "! How can I help you today?")
							.build();
				}
			}).buildToContext();
		
	}
}
 

Alternatively, if you're not using any XML file to initialize your context, you can always use the following methods.

// Call this upon initialization of your app (should only be called once)
KikBotMillLoader.getLoader().loadEntryPoint(new KikBotEntryPoint());

//	Call this on your callback url post handler (req = HttpRequest, Resp = HttpResponse).
KikBotMillLoader.getLoader().postHandler(req, resp); 

On Spark Java

import static spark.Spark.*;
			
public class KikBot {
    public static void main(String[] args) {
		// called once.
    	KikBotMillLoader.getLoader().loadEntryPoint(new KikBotEntryPoint());
    	 
    	//	register post (use this as webhook url on the config entrypoint);
    	post("/webhook", (request, response) -> {
	    	KikBotMillLoader.getLoader().postHandler(req, resp); 
		});
    }
}

On Spring Boot

@SpringBootApplication
public class KikBotConfiguration {

	public static void main(String[] args) {
	    //	call the loader inside the Hell
	    SpringApplication.run(KikBotConfiguration.class, args); 
	    
	    //	and load Entry Point.
	    KikBotMillLoader.getLoader().loadEntryPoint(new KikBotEntryPoint());
		
	}

}
@Controller
public class RestfulSourceController {

    @Autowired
    Response response;
    
	@Autowired
    Request request;
    
    @RequestMapping(value="/webhoolurl", method=RequestMethod.POST, produces="application/json")
    @ResponseBody
    public void post() {
        return KikBotMillLoader.getLoader().postHandler(request, response); 
    }

}

What's currently supported

Kik-BotMill supports this Kik Messenger Platform components:

  • Authentication
  • Configuration
  • Sending and Receiving Messages
    • Text
    • Link
    • Picture
    • Video
    • Start Chatting
    • Scan Data
    • Sticker
    • Is Typing
    • Delivery Receipt
    • Read Receipt
    • Friend Picker
  • Keyboards
  • Attributions
  • Broadcasting
  • User Profiles
  • Kik Codes

Copyright (c) 2017 BotMill.io

About

A Java framework for building bots on Kik Messenger Platform

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%