This repository is no longer mantained. Using of Instagram bots may cause blocking of your profile.
Simple framework for building Instagram chat bots with menu driven interface
pip3 install instachatbot
To install development version:
pip3 install git+https://github.com/art-vasilyev/instachatbot.git
Create sample script main.py
:
from instachatbot.bot import InstagramChatBot
from instachatbot.nodes import (
MenuNode, MenuItem, MessageNode, QuestionnaireNode, NotifyAdminNode)
menu = MenuNode(
'๐กChoose menu:\n',
[
MenuItem(
'text message',
MessageNode('This is a message๐')),
MenuItem(
'questionnaire',
QuestionnaireNode(
[
'What is your favourite book? ๐',
'What is your favourite fruit? ๐ ๐ ๐'
],
header='Please answer the following questions',
admin_username='<user to send results to>',
response='Thank your for your answers')),
MenuItem(
'send notification to admin',
NotifyAdminNode(
'Thank you',
notification='Sample notification from bot user',
admin_username='<username to send notification to>'
)
),
],
error_message='Failed to select menu.'
)
chatbot = InstagramChatBot(menu=menu)
chatbot.login(
username='<instagram-username>',
password='<instagram-password>')
chatbot.start()
Run the script:
python3 main.py
By default conversation state is discarded on bot restart, to make it persistent you should provide persistent storage on bot initialization:
chatbot = InstagramChatBot(menu=menu, storage=FileStorage())
By default a bot sends the menu on any message it receives. If you want menu to appear only if bot receives special message, set trigger
argument on bot initialization:
chatbot = InstagramChatBot(menu=menu, trigger='/menu')
Nested menu example:
menu = MenuNode(
'Main menu:\n',
[
MenuItem(
'Send message to admin',
MenuNode(
'Are you sure want to send message?',
[
MenuItem(
'Yes',
NotifyAdminNode(
'Thank you',
notification='Sample notification from bot user',
admin_username='<username to send notification to>'
)
),
MenuItem(
'No',
MessageNode('Canceled message sending.')
),
],
)
)
],
error_message='Failed to select menu.'
)