![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Opensource python wrapper to Messenger API
Install Pynani with pip
pip install pynani
Or install with pipenv (requires pipenv installed)
pipenv install pynani
The Messenger class (defined in Messenger.py) encapsulates all API calls in a single class. It provides functions such as send_xyz (send_message, send_attachment etc.) and several ways to listen for incoming messages.
Create a file called echo_bot.py. Then, open the file and create an instance of the Messenger class.
from pynani import Messenger
PAGE_ACCESS_TOKEN = 'EAAxxxxxxx...'
mess = Messenger(PAGE_ACCESS_TOKEN)
[!IMPORTANT] Make sure to actually replace PAGE_ACCESS_TOKEN with your own page access token.
After that declaration, we need to register some message handlers. First, we need to create and verify a webhook with the help of Flask or FastAPI.
from flask import Flask, request, jsonify
app = Flask(__name__)
TOKEN = "abc123"
@app.get("/")
def meta_verify():
return mess.verify_token(request.args, TOKEN)
Now let's define a webhook that handles certain messages
@app.post("/")
def meta_webhook():
data = request.get_json()
sender_id = mess.get_sender_id(data)
message = mess.get_message_text(data)
if message == "Hello":
mess.send_text_message(sender_id, "Hello, World!")
if message == "Bye":
mess.send_text_message(sender_id, "Nice to meet you! 👍🏽")
return jsonify({"status": "success"}), 200
We now have a basic bot which replies a static message to "hello" and "bye" messages. To start the bot, add the following to our source file:
if __name__ =='__main__':
app.run(port=8080, debug=True)
Alright, that's it! Our source file now looks like this:
from flask import Flask, request, jsonify
from pynani import Messenger
PAGE_ACCESS_TOKEN = 'EAAxxxxxxx...'
TOKEN = "abc123"
mess = Messenger(PAGE_ACCESS_TOKEN)
app = Flask(__name__)
@app.get("/")
def meta_verify():
return mess.verify_token(request.args, TOKEN)
@app.post("/")
def meta_webhook():
data = request.get_json()
sender_id = mess.get_sender_id(data)
message = mess.get_message_text(data)
if message == "Hello":
mess.send_text_message(sender_id, "Hello, World!")
if message == "Bye":
mess.send_text_message(sender_id, "Nice to meet you! 👍🏽")
return jsonify({"status": "success"}), 200
if __name__ =='__main__':
app.run(port=8080, debug=True)
To start the bot, simply open up a terminal and enter python echo_bot.py
to run the bot! Test it by sending messages ("hello" and "bye").
Here are some related projects that I was inspired by them.
FAQs
A package to wrap the Messenger API
We found that pynani demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.