tr{{tutorialPage.pythonSupport}}
tr{{tutorialPage.install}}
pip install --upgrade mailru-im-bot
tr{{tutorialPage.or}}
git clone https://github.com/mail-ru-im/bot-python.git
cd bot-python
python setup.py install
tr{{tutorialPage.registerFirstStep}}
tr{{tutorialPage.libraryExample}}
from bot.bot import Bot
from bot.handler import MessageHandler
TOKEN = "" #your token here
bot = Bot(token=TOKEN)
def message_cb(bot, event):
bot.send_text(chat_id=event.from_chat, text=event.text)
bot.dispatcher.add_handler(MessageHandler(callback=message_cb))
bot.start_polling()
bot.idle()
tr{{tutorialPage.library1}}
from bot.bot import Bot
tr{{tutorialPage.library2}}
from bot.handler import MessageHandler
tr{{tutorialPage.library3}} @metabot
TOKEN = ""
bot = Bot(token=TOKEN)
tr{{tutorialPage.library4}}
def message_cb(bot, event):
bot.send_text(chat_id=event.from_chat, text=event.text)
tr{{tutorialPage.library5}}
bot.dispatcher.add_handler(MessageHandler(callback=message_cb))
tr{{tutorialPage.library6}}
tr{{tutorialPage.library7}}
bot.start_polling()
tr{{tutorialPage.library8}}
bot.idle()
tr{{tutorialPage.chat1}} @metabot, tr{{tutorialPage.chat2}} /setjoingroups , tr{{tutorialPage.chat3}} enable . tr{{tutorialPage.chat4}} tr{{tutorialPage.chat5}}
print(event) #Event(type='EventType.NEW_MESSAGE', data='{'chat': {'chatId': '682502386@chat.agent', ...
some_nick = '' #nick, stamp or chat_id
bot.send_text(chat_id=some_nick, text="Hello, I'm a very fledged bot!")
tr{{tutorialPage.chat9}}
tr{{tutorialPage.chat10}} https://teams.vk.com/test_chat, tr{{tutorialPage.chat11}} - test_chat
Stamp - tr{{tutorialPage.chat12}} https://teams.vk.com/AoLFuNFynm67V2xGFX0. tr{{tutorialPage.chat13}} AoLFuNFynm67V2xGFX0
Chat_id - tr{{tutorialPage.chat14}}
tr{{tutorialPage.chat15}}
import schedule
import time
from bot.bot import Bot
TOKEN = "" #your token here
bot = Bot(token=TOKEN)
chats_to_send_notifications = [
"chat_to_recieve_messages", #nick of a public group chat
"AoLFuNFynm67V2xGFX0", #stamp of private group chat
"some_user_nickname", #nick of a person
"682502386@chat.agent" # default chat id
]
text_to_send = "Let's go home!"
def send_alert():
for chat in chats_to_send_notifications:
bot.send_text(chat_id=chat, text=text_to_send)
schedule.every().day.at("19:00").do(send_alert)
while True:
schedule.run_pending()
time.sleep(1)
tr{{tutorialPage.chat16}}
import schedule
import time
from bot.bot import Bot
tr{{tutorialPage.chat17}}:
TOKEN = "" #your token here
bot = Bot(token=TOKEN)
tr{{tutorialPage.chat18}}:
chats_to_send_notifications = [
"chat_to_recieve_messages", #nick of a public group chat
"AoLFuNFynm67V2xGFX0", #stamp of private group chat
"some_user_nickname", #nick of a person
"682502386@chat.agent" # default chat id
]
text_to_send = "Let's go home!"
tr{{tutorialPage.chat19}}:
def send_alert():
for chat in chats_to_send_notifications:
bot.send_text(chat_id=chat, text=text_to_send)
tr{{tutorialPage.chat20}}:
schedule.every().day.at("19:00").do(send_alert)
while True:
schedule.run_pending()
time.sleep(1)
tr{{tutorialPage.buttons1}} github.com/shvedoff/Icq_buttons
tr{{tutorialPage.buttons2}}: tr{{tutorialPage.buttons3}} inline_keyboard_markup:
bot.send_text(chat_id=OWNER,
bot.send_text(chat_id=event.from_chat,
text="Hello with buttons.",
inline_keyboard_markup="{}".format(json.dumps([[
{"text": "Action 1", "url": "https://teams.vk.com"},
{"text": "Action 2", "callbackData": "call_back_id_2", "style": "attention"},
{"text": "Action 3", "callbackData": "call_back_id_2", "style": "primary"}
]])))
tr{{tutorialPage.buttons4}}
bot.dispatcher.add_handler(BotButtonCommandHandler(callback=buttons_answer_cb))
def buttons_answer_cb(bot, event):
if event.data['callbackData'] == "call_back_id_1":
bot.answer_callback_query(
query_id=event.data['queryId'],
text="Hey! It's a working button 2.",
show_alert=True
)
elif event.data['callbackData'] == "call_back_id_2":
bot.answer_callback_query(
query_id=event.data['queryId'],
text="Hey! It's a working button 3.",
show_alert=False
)
import json
from bot.bot import Bot
from bot.handler import MessageHandler, BotButtonCommandHandler
TOKEN = "" #your token here
bot = Bot(token=TOKEN)
def buttons_answer_cb(bot, event):
if event.data['callbackData'] == "call_back_id_2":
bot.answer_callback_query(
query_id=event.data['queryId'],
text="Hey! It's a working button 2.",
show_alert=True
)
elif event.data['callbackData'] == "call_back_id_3":
bot.answer_callback_query(
query_id=event.data['queryId'],
text="Hey! It's a working button 3.",
show_alert=False
)
def message_cb(bot, event):
bot.send_text(chat_id=event.from_chat,
text="Hello with buttons.",
inline_keyboard_markup="{}".format(json.dumps([[
{"text": "Action 1", "url": "https://teams.vk.com"},
{"text": "Action 2", "callbackData": "call_back_id_2", "style": "attention"},
{"text": "Action 3", "callbackData": "call_back_id_2", "style": "primary"}
]])))
bot.dispatcher.add_handler(MessageHandler(callback=message_cb))
bot.dispatcher.add_handler(BotButtonCommandHandler(callback=buttons_answer_cb))
bot.start_polling()
bot.idle()
tr{{tutorialPage.format1}}
tr{{tutorialPage.format2}}
bold
- tr{{mainPage.formatBold}}italic
- tr{{mainPage.formatItalic}}underline
- tr{{mainPage.formatUnderline}}strikethrough
- tr{{mainPage.formatStrikethrough}}link
- tr{{mainPage.formatLink}}mention
- tr{{mainPage.formatMention}}inline_code
- tr{{mainPage.formatInlineCode}}pre
- tr{{mainPage.formatPre}}ordered_list
- tr{{mainPage.formatOrderedList}}unordered_list
- tr{{mainPage.formatUnorderedList}}quote
- tr{{mainPage.formatQuote}}tr{{tutorialPage.format3}}
bold
: pre
italic
: pre
underline
: pre
strikethrough
: pre
link
: mention
, pre
mention
: link
, pre
inline_code
: pre
pre
: bold
, italic
, underline
, strikethrough
, link
, mention
, inline_code
, ordered_list
, unordered_list
, quote
ordered_list
: pre
, unordered_list
, quote
unordered_list
: pre
, ordered_list
, quote
quote
: pre
, ordered_list
, unordered_list
tr{{tutorialPage.format4}}
{ "bold": [ { "offset": 0, "length": 1 }, { "offset": 2, "length": 5 } ], "italic": [ { "offset": 2, "length": 3 } ] }
offset
tr{{tutorialPage.format5}}
length
tr{{tutorialPage.format6}}
tr{{tutorialPage.format7}}
tr{{tutorialPage.format8}}
tr{{tutorialPage.format9}}
*bold* _italic_ __underline__ ~strikethrought~ [url](https://example.com) [mention] `inline_code` ``` pre-formatted fixed-width code block ``` ```python pre-formatted fixed-width code block written in the Python programming language ``` Ordered list: 1. First element 2. Second element Unordered list: - First element - Second element Quote: >Begin of quote >End of quote
tr{{tutorialPage.format10}}
tr{{tutorialPage.format11}}
<
- <
>
- >
&
- &
tr{{tutorialPage.format9}}
<b>bold</b>, <strong>bold</strong> <i>italic</i>, <em>italic</em> <u>underline</u>, <ins>underline</ins> <s>strikethrough</s>, <strike>strikethrough</strike>, <del>strikethrough</del> <a href="http://www.example.com/">inline URL</a> <a>inline mention of a user</a> <code>inline fixed-width code</code> <pre>pre-formatted fixed-width code block</pre> <pre><code class="python">pre-formatted fixed-width code block written in the Python programming language</code></pre> Ordered list: <ol> <li>First element</li> <li>Second element</li> </ol> Unordered list: <ul> <li>First element</li> <li>Second element</li> </ul> Quote: <blockquote> Begin of quote. End of quote. </blockquote>