Docs/Menu actions
Menu actions
Add a command to a chat, a message or a profile.
A chat menu action
Register an item in on_plugin_load. Its callback receives the context of the tap. This example displays the account slot associated with the menu.
from base_plugin import BasePlugin, MenuItemData, MenuItemType
from ui.bulletin import BulletinHelper
class AccountHint(BasePlugin):
def on_plugin_load(self):
self.menu_id = self.add_menu_item(MenuItemData(
menu_type=MenuItemType.CHAT_ACTION_MENU,
text="Show account",
on_click=self.show_account,
))
def show_account(self, context):
account = context.get("account")
if account is not None:
BulletinHelper.show_info(f"Account: {account}")
Add the fields from Metadata before installing this class in a standalone file.
Where the action appears
MenuItemType value |
Location |
|---|---|
CHAT_ACTION_MENU |
Chat actions menu. |
MESSAGE_CONTEXT_MENU |
Context menu for a message. |
PROFILE_ACTION_MENU |
Profile menu. |
DRAWER_MENU |
Side drawer in layouts that provide one. |
Removing an item
add_menu_item returns the registered item ID or None. To remove the action while the plugin is running, check the returned ID and pass it to self.remove_menu_item(self.menu_id).