Async Python SDK for the social-media-automations Instagram Bot API
Project description
social-media-automations (Python SDK)
Async Python client for the Instagram Bot API — register handlers, call run_polling().
Install
pip install social-media-automations
For local development from a clone: pip install -e ".[dev]"
Quickstart
from social_media_automations import Bot
app = Bot(account_key="ak_...") # your Account Key
@app.on_message()
async def on_dm(msg, ctx):
await ctx.reply(f"Hi {msg.from_user.username}!")
@app.on_message(text="price") # case-insensitive substring; or regex="..."
async def price(msg, ctx):
await ctx.reply("$6/mo")
@app.on_comment()
async def on_comment(c, ctx):
await ctx.reply_comment("Thanks!")
@app.on_postback(payload="book") # exact payload; or regex="..."
async def on_btn(pb, ctx):
await ctx.reply("Let's get you booked!")
app.run_polling()
Handler reference
@app.on_message(text=None, regex=None)— DMs.text= case-insensitive substring;regex=re.search; pass at most one.@app.on_comment()— public comments.@app.on_postback(payload=None, regex=None)— button/ice-breaker taps (pb.payload).payload= exact match;regex=re.search; pass at most one.
Handlers are async def handler(obj, ctx). First matching handler wins.
Context (ctx)
await ctx.reply(text)— DM the sender.await ctx.reply_comment(text)— public reply (comment handlers only).await ctx.send(to, text)— DM an arbitrary IG-scoped id on this channel.
Notes
- One channel must be in bot mode first (
POST /bot/v1/setDeliveryMode). - Polling is at-least-once;
msg.id/comment.idare stable for dedup. Ctrl-Cstops the bot cleanly.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file
social_media_automations-0.1.1.tar.gz.File metadata
File hashes
bf0cb9b24e83da99104a09b87648b0931b34b10a8815b815bb2fff08f6c5a4fd27e9ce44a9db1818a59cfe8c0b23f9d153304d55b7312c5b2d72a956047de82b66445b97eadf34aecf8e04cba3f729f0See more details on using hashes here.