Skip to content

Commit

Permalink
fix: unable to set welcome screen in profile api
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna2206 committed May 19, 2022
1 parent 66ca6d6 commit 48eb032
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
Binary file modified dist/messenger-api-python-2022.5.19.tar.gz
Binary file not shown.
Binary file modified dist/messenger_api_python-2022.5.19-py3-none-any.whl
Binary file not shown.
14 changes: 1 addition & 13 deletions messenger_api_python.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,8 @@ Various components used when sending messages in Facebook Messenger are wrapped
- You'll need to setup a [Facebook App](https://developers.facebook.com/apps/), Facebook Page, get the Page Access Token and link the App to the Page.
## How to install
### From GitHub
- Clone this repository :
```bash
git clone https://github.com/krishna2206/messenger-api-python.git
```
- Navigate to the cloned repository folder and build the package :
```bash
python -m build
```
- Navigate to *dist* folder and install the package, <package_name> may vary so I don't explicitly provide the name here :
```bash
pip install <package_name>.whl
pip install git+https://github.com/krishna2206/messenger-api-python.git#egg=messenger-api-python
```
### 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)
Expand All @@ -77,8 +68,6 @@ send_api.send_text_message(<message>, <recipient_id>)

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

> If `app_secret` is initialized, an app_secret_proof will be generated and send with every request. Appsecret Proofs helps further secure your client access tokens. You can find out more on the [Facebook Docs](https://developers.facebook.com/docs/graph-api/securing-requests#appsecret_proof)

##### Sending a generic template message:

> [Generic Template Messages](https://developers.facebook.com/docs/messenger-platform/implementation#receive_message) allows you to add cool elements like images, text all in a single bubble.
Expand Down Expand Up @@ -130,4 +119,3 @@ send_api.send_local_file(<file_location> , <recipient_id>)
```
## To do
- Securing requests
- Unit tests
6 changes: 3 additions & 3 deletions messenger_api_python.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
python_magic==0.4.25
requests==2.26.0
requests_toolbelt==0.9.1
python_magic
requests
requests_toolbelt
21 changes: 10 additions & 11 deletions messengerapi/messenger_profile_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def __init__(self , page_access_token):
self.__graph_version = "13.0"
self.__api_url = f"https://graph.facebook.com/v{self.__graph_version}/me"
self.__page_access_token = page_access_token
self.__global_level_endpoint = "/messenger_profile"
self.__user_level_endpoint = "/custom_user_settings"

def get_api_url(self):
return self.__api_url
Expand Down Expand Up @@ -43,7 +45,10 @@ def set_welcome_screen(self , get_started_button_payload , greetings=None):
"greeting" : greetings
}

return requests.post(self.get_api_url() , params={"access_token":self.get_access_token()} , json=request_body).json()
return requests.post(
self.get_api_url() + self.__global_level_endpoint,
params={"access_token":self.get_access_token()} ,
json=request_body).json()

def set_user_persistent_menu(self, user_id, persistent_menu):
"""Set the persistent menu for any user of the page.
Expand All @@ -52,29 +57,23 @@ def set_user_persistent_menu(self, user_id, persistent_menu):
user_id (str) : The user id.
persistent_menu (PersistentMenu object) : The content of the PersistentMenu object , obtained via the PersistentMenu().get_content() method.
"""
user_level_endpoint = "/custom_user_settings"

return requests.post(
self.get_api_url() + user_level_endpoint,
self.get_api_url() + self.__user_level_endpoint,
params={"access_token":self.get_access_token()},
json={
"psid": user_id,
"persistent_menu": persistent_menu
}
).json()
}).json()

def set_persistent_menu(self, persistent_menu):
"""Set the persistent menu for the page.
Args:
persistent_menu (PersistentMenu object) : The content of the PersistentMenu object , obtained via the PersistentMenu().get_content() method.
"""
global_level_endpoint = "/messenger_profile"

return requests.post(
self.get_api_url() + global_level_endpoint,
self.get_api_url() + self.__global_level_endpoint,
params={"access_token": self.get_access_token()},
json={
"persistent_menu": persistent_menu
}
).json()
json={"persistent_menu": persistent_menu}).json()

0 comments on commit 48eb032

Please sign in to comment.