JM Tech Power

Guides

Write your own JM Chat bot: one key, three API calls, and a log of everything it reads

← All articles Email RSS Atom

A JM Chat bot is a chat account you own that a program runs: a script on your server, a home-automation box, or JJ Bot. People write to it like anyone else, and your program reads and answers through a small API. Here is how to build one.

1. Make the bot

  1. Open My bots (in JM Chat, the 🤖 My bots link under the search box).
  2. Type a name and press Make bot. Its username is made from the name and ends in -bot. You can have up to 5 bots.
  3. Copy the key straight away: it starts with jmb_ and is shown once.

The bot is its own account, never yours: it cannot sign in, and its key works only on the bot API, nowhere else on the site.

2. Three calls

Send the key as Authorization: Bearer jmb_… on each request.

curl -H "Authorization: Bearer $JMB_KEY" https://jmtechpower.com/api/v1/bot/me

curl -H "Authorization: Bearer $JMB_KEY" "https://jmtechpower.com/api/v1/bot/messages?after=0"

curl -X POST -H "Authorization: Bearer $JMB_KEY" \
     -H "Content-Type: application/json" \
     -d '{"user_id": 42, "text": "Hello!"}' https://jmtechpower.com/api/v1/bot/send
  • /me gives the bot's id, name, owner and groups.
  • /messages returns new messages oldest first, up to 100 at a time. Keep next_after and pass it as ?after= next time; has_more says there are more waiting. The bot's own messages and unsent ones are left out, and for a file it gets the name and size, not the file.
  • /send takes user_id or group_id, the text, and optionally reply_to_id.

3. What a bot may do

  • It reads private chats with it, and groups a member added it to — only messages sent after it was added.
  • It can write first only to you. Anyone else has to write to it first; until then /send answers 403.
  • At most 30 messages a minute (then 429) and 4000 characters a message.
  • Everyone sees a BOT tag beside its name, and a group with a bot shows a note saying so.

To put it in a group, write to the bot once, then open the group, press ⚙ Manage, tick it under Add members and press Add selected. Any member can take it out again with Remove in the group's bot note.

4. Keep an eye on it

Each bot's card on My bots shows when its key was last used, the groups it is in, and What it did lately: every read and send, with the time (UTC), the chat and the message numbers. Lost the key, or think it leaked? New key makes a fresh one and the old one stops working at once. Turn off removes the key and takes the bot out of every group; its old messages stay.

The full reference is under JM Chat bots on the API docs page. Using JJ Bot? See talk to your bot in JM Chat. More guides at https://jmtechpower.com/articles.

Comments (0)

No comments yet. Be the first to comment!