A Telegram Chatbot for Kanboard with NodeRED

Context

I’ve used a number of todo list applications over the years.

I have recently decided to use a simple kanban with three columns (todo/wip/done) as my todo list, and it works wonders.

I self-host a Kanboard instance, so I have full control over my boards.

I no longer depend on a company that could decide to shut down the service overnight (not looking at you, Microsoft [after purchasing Wunderlist]).

In my article about my desktop environment, I cover how I even integrated Kanboard in my i3 bar.

Obviously, mobile apps are the strong point of proprietary solutions, while the Android app for Kanboard is not as advanced.

I wanted to implement an easy way to add tasks to my kanban boards, and since Kanboard has an API, how about using a Telegram bot?

Here we go!

Requirements

The workflow

Create the bot

Use BotFather to create your new bot.

Configure the bot:

Nodes

The query to Kanboard API should be done with the http request node:

getAllTasks node:

msg.chatId = msg.payload.chatId;
var item = msg.payload.content.replace(/^\s+/g, '');
msg.payload = "{\"jsonrpc\": \"2.0\", \"method\": \"getAllTasks\", \"id\": 1, \"params\": {\"project_id\": 6}}";
return msg;

createTask node:

Change the project ID number.

msg.chatId = msg.payload.chatId;
msg.item = msg.payload.content.replace(/^\s+/g, '');
msg.payload = "{\"jsonrpc\": \"2.0\", \"method\": \"createTask\", \"id\": 1, \"params\": {\"title\": \"" + msg.item + "\", \"project_id\": 6}}";
return msg;

Generate the reply list:

Change the column ID.

var items = msg.payload.result;

msg.payload.chatId = msg.chatId;
msg.payload.type = 'message';
msg.task = [];

// this will generate an array with "null" for tasks not in column 20
for(var i = 0; i < items.length; i++) {
   if(items[i].column_id === '20') {
     msg.task[i] = "- " + items[i].title + "\n";
   }
}

// remove null entries
msg.cleaned = msg.task.filter(n => n)
// turn array into string
var list = msg.cleaned.join("");
// message
if(list === "") {
    msg.payload.content = "Nothing in the list."
} else {
msg.payload.content = list;
}

return [ msg ];

Generate the reply todo:

If you make your board public, you can share in the reply.

msg.payload.chatId = msg.chatId;
msg.payload.type = 'message';
msg.payload.content = 'Added "'+ msg.item + '" to your todo list.\n\nFull list at https://kanban.example.org/public/board/XXX';
return [ msg ];

Result




Thanks for reading this post!


Did you find an issue in this article?

- click on the following Github link
- log into Github with your account
- click on the line number containing the error
- click on the "..." button
- choose "Reference in new issue"
- add a title and your comment
- click "Submit new issue"

Your feedback is much appreciated! πŸ€œπŸΌπŸ€›πŸΌ

You can also drop me a line below!