Skip to content

feat: add /hive command to create Hive tasks from Telegram - #5

Open
mainshivam wants to merge 2 commits into
bwhtech:developfrom
mainshivam:feat/hive-task-command
Open

feat: add /hive command to create Hive tasks from Telegram#5
mainshivam wants to merge 2 commits into
bwhtech:developfrom
mainshivam:feat/hive-task-command

Conversation

@mainshivam

Copy link
Copy Markdown
Collaborator

Why?

The bot could only do HR flows (leave, WFH, petty cash), all of which need Frappe HR. Teams running Hive without HR or ERPNext had nothing they could use, and the app could not even be installed on such a site.

What?

A /hive command that creates a Hive Task from Telegram, with no HR dependency.

The flow: task title -> optional description -> start date -> end date -> project picker -> assignee picker (multi-select, tap to toggle) -> review -> create.

Projects come from open, non-archived Hive Project records. Assignees come from active Hive Member records of type Team, and are written to the standard _assign field, matching how Hive tracks them.

How?

Making this work without HR needed three supporting changes:

  • BotConversation gains requires_employee (default True, so leave and WFH behave exactly as before) and required_doctypes. Commands are registered process-wide, so a site missing the owning app now gets a readable message instead of a traceback part way through a conversation.
  • install.py skips custom fields whose doctype is absent. Previously a site without HR failed to install the app at all, because after_install created a field on Attendance Request. after_migrate re-runs it, so the field still appears if HR is installed later.
  • The daily leave/WFH broadcasts and the monthly petty cash job return early when their doctypes are missing, rather than raising on schedule.

Also fixed

Every command in the Telegram menu showed the same description, "Apply for Work From Home".

Each conversation registers the same bound BotConversation.handle_command, so fn.__func__._description = description wrote to one shared function object and the last registration won for all of them. /ping was unaffected because it is a plain function. Descriptions now live in a dict keyed by command.

Tests

Adds bwh_bot/tests/test_hive.py, 15 tests, the first in this app:

  • task creation with all fields, assignees landing in _assign
  • skipping the description, creating with no assignees
  • assignee toggle on and off
  • end date before start rejected, empty title rejected
  • back navigation, archived projects excluded
  • the dependency gate, and a regression test for the description bug

Run with:

bench --site <site> run-tests --app bwh_bot --module bwh_bot.tests.test_hive

Verified on

A site with Hive but no HR and no ERPNext (frappe, raven, bwh_hive, drive, bwh_bot), plus a site with HR installed to confirm leave and WFH are unchanged.

@mainshivam
mainshivam force-pushed the feat/hive-task-command branch from edee350 to 71587d1 Compare July 29, 2026 15:54
Adds a conversation handler that walks the user through creating a Hive
Task: title, optional description, start date, end date, project picker
and a multi-select assignee picker.

The flow has no Frappe HR dependency, so it works on sites that run Hive
without HR or ERPNext. Supporting changes for that:

- BotConversation gains `requires_employee` (default True, so leave and
  WFH are unchanged) and `required_doctypes`. Commands are registered
  process-wide, so a site missing the owning app now gets a readable
  message instead of a traceback.
- install.py skips custom fields whose doctype is absent. Previously the
  whole install failed on a site without HR because it created a field
  on Attendance Request. after_migrate re-runs it, so the field still
  appears if HR is installed later.
- The daily leave/WFH broadcasts and the monthly petty cash job return
  early when their doctypes are missing, instead of raising on schedule.

Assignees are written to the standard `_assign` field, matching how Hive
tracks them.

Also fixes the command descriptions shown in the Telegram menu. Every
conversation registers the same bound BotConversation.handle_command, so
storing the description on the function object meant each registration
overwrote the previous one and all commands ended up showing the last
one ("Apply for Work From Home"). Descriptions now live in a dict keyed
by command.

Adds bwh_bot/tests/test_hive.py: 15 tests covering the flow, validation,
navigation, the dependency gate and the description regression.
CI runs pre-commit with --all-files, and the committed tree did not
satisfy the repo's own ruff config, so every pull request failed the
linter before reaching its own changes. The linter job only runs on
pull_request, which is why this drift was never caught on develop.

Formatting only, plus RUF005 (use iterable unpacking instead of list
concatenation) in confirm_buttons and the two _summary_buttons helpers.
No behaviour changes.
@mainshivam
mainshivam force-pushed the feat/hive-task-command branch from 71587d1 to 4b203f5 Compare July 29, 2026 15:58
@mainshivam
mainshivam requested a review from gajjug004 July 29, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant