A note in the chat menu
Connect a preference to a chat action and test the result.
Try the plugin
Download note-en.plugin, send it to Saved Messages as a document and open it in the GitHub edition. Install and enable Chat note. Open a chat and select ⋮ → My note. A bulletin reads “Check the list”. The action does not send anything to the conversation.
Change the note
Open Note text in the plugin settings, enter “Call this evening” and save it. Go back to the chat and select My note again. The new text should appear immediately. Close and reopen the settings screen to check it was saved.
Follow the callback
The engine calls on_plugin_load when you enable the plugin. This is where the example registers its menu action. Pass the method self.show_note to on_click. The engine calls it later with the context of the tap. Adding parentheses would call the method during registration.
The Input row and get_setting share the key note. The callback reads the value on each tap, so edits take effect without restarting. Empty and whitespace-only input fall back to the original note.
__id__ = "sdk_chat_note"
__name__ = "Chat note"
__description__ = "Shows a saved note from the chat menu."
__author__ = "NimarkoGram"
__version__ = "1.0"
__host__ = "NimarkoGram"
__sdk_version__ = ">=1.0"
__required_apis__ = ["add_menu_item", "get_setting"]
from base_plugin import BasePlugin, MenuItemData, MenuItemType
from ui.bulletin import BulletinHelper
from ui.settings import Input
DEFAULT_NOTE = "Check the list"
class ChatNote(BasePlugin):
def create_settings(self):
return [Input(key="note", text="Note text", default=DEFAULT_NOTE)]
def on_plugin_load(self):
self.add_menu_item(MenuItemData(
menu_type=MenuItemType.CHAT_ACTION_MENU,
text="My note",
on_click=self.show_note,
))
def show_note(self, context):
note = self.get_setting("note", DEFAULT_NOTE)
BulletinHelper.show_info(note.strip() or DEFAULT_NOTE)
Verify the scope
Change the text in the plugin settings, then open the note in two different chats. Both use the same value because the setting belongs to the plugin. See Multiple accounts to scope a preference to an account, then test an in-place upgrade.