Skip to main content

Router for chatbot

Project description

quick example

#-*-coding:utf8;-*-
import chatrouter


chatbot = chatrouter.group("test")
	
@chatbot.add_command("/start", description="start command", strict=True)
def start_handler():
	return "this is start command!"

@chatbot.add_command("call me {nama}")
def say_handler(nama):
	return f"hello {nama}, nice to meet you!"

@chatbot.add_command("repeat me {satu} and {dua}")
def repeat_handler(satu, dua):
	return f"ok {satu}.. {dua}"
	
@chatbot.add_default_command()
def default_handler(command):
	return f"command {command} not found!"

if __name__ == '__main__':
	print("Welcome to chatrouter demo! type /help to show help messages.")
	while True:
		try:
			i = input("you: ")
			r = chatrouter.run(chatbot, i)
			print(f"bot: {r}")
		except BaseException as e:
			print("bot: byebye!")
			exit(0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatrouter-0.0.1.tar.gz (2.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page