Skip to main content

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 — all bot-mode channels

# ...or scope updates to specific channels (server-side filter):
app = Bot(account_key="ak_...", channel_ids=["ch-1", "ch-2"])

@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.id are stable for dedup.
  • Ctrl-C stops 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

social_media_automations-0.1.4.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

social_media_automations-0.1.4-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file social_media_automations-0.1.4.tar.gz.

File metadata

File hashes

Hashes for social_media_automations-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ea76e28c52bc0931c32ee9a7c9666c846b3f3aeacef5816af9cdf558a2e1c6b8
MD5 1b19ba4d743cdec3ac5beae838030d22
BLAKE2b-256 6eaff5662e3e600e55bcb69ad932aec4299c8e515669ca71680799765ab1c7f6

See more details on using hashes here.

File details

Details for the file social_media_automations-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for social_media_automations-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c970fcb600b79f89b557a5d9f9d474de31cc312f088ba73f6c8c44f3a12e61bf
MD5 2645417e0ac6d6a1d70c0c37b4ffce78
BLAKE2b-256 2bf731698ec838da86bfb3fafaeba0803225d83b6b5de3c15140984a77ba772f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page