Skip to main content

meta_api_python

Python Wrapper to various APIs from Meta Platform.

Features

Send API (v16.0)

  • Send text messages
  • Send Media from a remote file (image, audio, video, file)
  • Send Action
  • Send quick replies
  • Send buttons
  • Send Generic Messages

Prerequisite

  • Python 3.7+ installed
  • You'll need to setup a Meta App, Facebook Page, get the Page Access Token and link the App to the Page.

How to install

From GitHub

pip install git+https://github.com/santoshdahal2016/meta-api-python.git

From Pypi

Package from Pypi.org may not be the latest one, if you want the latest version of this package, install it from the GitHub repository (see above)

pip install meta-api-python

Usage

Send API

from meta.api.api import Api
from meta.api.messages.text_message import TextMessage



api = Api(page_access_token=<page_access_token>)

text_message = TextMessage(text="Hi, How are you?")
response = api.send_messages(to= <recipient_id>, messages=text_message)

Note: From Facebook regarding Receipt IDs

These ids are page-scoped. These ids differ from those returned from Meta Login apps which are app-scoped. You must use ids retrieved from a Messenger integration for this page in order to function properly.

Sending a generic template message:

Generic Template Messages allows you to add cool elements like images, text all in a single bubble.

from metapython import Api

from metapython.api.consts import ButtonType
from metapython.api.messages import ElementMessage, ElementsMessage, ButtonMessage, ButtonsMessage


api = Api(page_access_token=<page_access_token>)

# Generic Message
elements = ElementsMessage()

web_link_button = ButtonMessage(button_type=ButtonType.WEB_URL, title="Visit Diyo Website")
web_link_button.set_url(<url>)

element1 = ElementMessage(
    buttons=[web_link_button],
    image_url="https://moneymitra.com/static/image/moneymitra-logo.png",
)
elements.add_element(element1)

phone_number_button = ButtonMessage(button_type=ButtonType.PHONE_NUMBER, title="Call me")
phone_number_button.set_payload("XXXXXXXXXXX")
element2 = ElementMessage(
    buttons=[phone_number_button],
    image_url=<image_url>,
)
elements.add_element(element2)

response = api.send_messages(to= <recipient_id>, messages=elements)

Metadata

Release files for meta-api-python 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for meta-api-python 0.1.0
File Interpreter ABI Platform
meta_api_python-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / meta_api_python-0.1.0-py3-none-any.whl

Download URL meta_api_python-0.1.0-py3-none-any.whl
Size 29.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81d856b00f2b177b3d19d9dd02edb4c41abf81e26a3851e1273e648f56a2bd99
BLAKE2b-256 checksum
How to use checksums
7710a8f6057034eeb9040630a490e9d2099eed3f2711e8606d7c9b244f49387c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page