I am working on fb chatbot and use postback in the generic templates buttons. However, there is no response after I click the postback button.
"buttons": [
{
"type": "web_url",
"url": "https://maps.google.com/?q={lat},{lon}".format(lat=store['coordinates']['lat'], lon=store['coordinates']['lon']),
"title": u"店家位置"
},
{
"type": "postback",
"payload": Function.sendGourmetComments + "_{id}".format(id=store["id"]),
"title": u"觀看評論"
},
{
"type": "postback",
"payload": Function.sendStoreHearts + "_{upload}".format(upload=None) + "_{id}".format(id=store["id"]) + "_{push}".format(push=None) + "_{edit}".format(edit=None) + "_{search}".format(search=True),
"title": u"撰寫評論"
}
]
I guess I didn't check the message_postback event, however, I did. I didn't even receive any response from my webhook. So it's kind of mysterious to me what's going on.
It was working fine before, but it doesn't work without change after restart my computer. I am using ngork to expose my server API as callback url.
I've this problem two days ago.
You need the page_messaging facebook's approve to receive it Facebook's approved page_messaging permission
Related
I am using the python slack bolt. https://api.slack.com/start/building/bolt-python#create
I created the example in the link and was able to make a home tab page but I want to create a modal from a message in a channel, not a home page view. I have looked everywhere for a basic example but I can't get any MODALS to work with what I have learned from slack's own documentation. This is the only examples I can find (which came from slack's own documentation after you read the starting out page).
Here is the test example that works but shows up with a home page instead of a modal:
SLACK_BOT_TOKEN="slackbottokenstring"
SLACK_SIGNING_SECRET="slacksigningsecretstring"
import os
# Use the package we installed
from slack_bolt import App
# Initializes your app with your bot token and signing secret
app = App(
token = SLACK_BOT_TOKEN,
signing_secret = SLACK_SIGNING_SECRET
# token=os.environ.get("SLACK_BOT_TOKEN"),
# signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
)
# Add functionality here
#app.event("app_home_opened")
def update_home_tab(client, event, logger):
try:
# views.publish is the method that your app uses to push a view to the Home tab
client.views_publish(
# the user that opened your app's app home
user_id=event["user"],
# the view object that appears in the app home
view={
"type": "home",
"callback_id": "home_view",
# body of the view
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Welcome to your _App's Home_* :tada:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This button won't do much for now but you can set up a listener for it using the `actions()` method and passing its unique `action_id`. See an example in the `examples` folder within your Bolt app."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Click me!"
}
}
]
}
]
}
)
except Exception as e:
logger.error(f"Error publishing home tab: {e}")
# Start your app
if __name__ == "__main__":
app.start(port=int(os.environ.get("PORT", 3000)))
And that works:
But if I try to change it to a modal, it fails:
CODE:
#app.event("app_home_opened")
def update_home_tab(client, event, logger):
try:
# views.publish is the method that your app uses to push a view to the Home tab
client.views_publish(
# the user that opened your app's app home
user_id=event["user"],
# the view object that appears in the app home
view={
"type": "modal",
"callback_id": "modal-identifier",
"title": {
"type": "plain_text",
"text": "Just a modal"
},
"blocks": [
{
"type": "section",
"block_id": "section-identifier",
"text": {
"type": "mrkdwn",
"text": "*Welcome* to ~my~ Block Kit _modal_!"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Just a button",
},
"action_id": "button-identifier",
}
}
],
}
)
Error:
127.0.0.1 - - [14/Aug/2022 15:21:15] "POST /slack/events HTTP/1.1" 200 -
Error publishing home tab: The request to the Slack API failed. (url: https://www.slack.com/api/views.publish)
The server responded with: {'ok': False, 'error': 'invalid_arguments', 'response_metadata': {'messages': ['[ERROR] failed to match all allowed schemas [json-pointer:/view]', '[ERROR] unsupported type: modal [json-pointer:/view/type]']}}
I am following the view structure design in a json object like it says here: https://api.slack.com/surfaces/modals/using#composing_views
I figured out what I had to do but it was kinda annoying, I want to just say that first. There are a couple reasons as to why it was annoying to figure out.
There is no direct python example from the website, BUT slack does have a github where they show a modal example.
Using specifically Modals require than just making text blocks in a chat. It requires some weird thing called a trigger_id which you get from initiating a specific response that would cause slack to send an object over to your endpoint. The problem is that there is no example of this. If you are going through slack's tutorial, they ONLY show you how to create a url for making a bot that event listens and responds to messages. You can make your own url using flask but since I am using the bolt slack module, they wrap there own stuff around flask which makes it hard to make basic decorators for flask. - In other words, the slack documentation is super confusing for modals and they don't have any real examples for modals with bolt python.
after doing days of research in my spare time, I was finally able to get an example working where you can COPY AND PASTE this code. You just need your bot token secret and signing key which you can set in your environment or as a string if you are just testing around in your local computer.
SLACK_BOT_TOKEN="slackbottokenstring"
SLACK_SIGNING_SECRET="slacksigningsecretstring"
import os
# Use the package we installed
from slack_bolt import App
from slack_bolt.adapter.flask import SlackRequestHandler
from flask import Flask, request
flask_app = Flask(__name__)
# Initializes your app with your bot token and signing secret
app = App(
token = SLACK_BOT_TOKEN,
signing_secret = SLACK_SIGNING_SECRET
# token=os.environ.get("SLACK_BOT_TOKEN"),
# signing_secret=os.environ.get("SLACK_SIGNING_SECRET")
)
handler = SlackRequestHandler(app)
#flask_app.route("/slack/events", methods=["POST"])
def slack_events():
return handler.handle(request)
#app.shortcut("SearchMessagesID")
def handle_shortcuts(ack, body, logger,client):
ack()
logger.info(body)
print(body)
res = client.views_open(
trigger_id=body["trigger_id"],
view={
"type": "modal",
"callback_id": "modal-identifier",
"title": {
"type": "plain_text",
"text": "Just a modal"
},
"blocks": [
{
"type": "section",
"block_id": "section-identifier",
"text": {
"type": "mrkdwn",
"text": "*Welcome* to ~my~ Block Kit _modal_!"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Just a button",
},
"action_id": "button-identifier",
}
}
],
}
)
# Start your app
if __name__ == "__main__":
app.start(port=int(os.environ.get("PORT", 3000)))
I use docusign every day and have set up a google sheet that auto populates the email subject and body.
I'm still having to copy and paste this data into the 'email subject' & 'email message'. See screenshot example.
Is there a way i can reduce this process to the click of a button?
Absolutely. Here's are two rough flows that would be helpful to pursue.
You could make use of the Google Apps Script to push data directly to DocuSign. Downside here is that you'd be writing the code in JavaScript.
You can write a short python app yourself, which uses the Google Sheets API (via python sdk) to retrieve your data, then pass along the appropriate info to the DocuSign eSignature API (via python sdk).
In either case, once you have access to the data you wish to forward to DocuSign, you will want to first authenticate your account to make API requests on your behalf.
Then you can make a request like this:
POST /envelopes
{
"emailSubject": "Please sign these documents",
"emailBlurb": "Thank you for subscribing. Click the link to sign",
"documents": [
{
"documentBase64": "JVBER...iUlRU9GCg==",
"name": "Test Doc",
"fileExtension": "pdf",
"documentId": "1"
}
],
"recipients": {
"signers": [
{
"email": "test#test.com",
"name": "Test User",
"recipientId": "1",
"routingOrder": "1",
"tabs": {
"numberTabs": [
{
"tabLabel": "PO #",
"locked": "false",
"xPosition": "200",
"yPosition": "200",
"documentId": "1",
"pageNumber": "1"
}
]
}
}
]
},
"status": "sent"
}
By using bot functionality provided by facebook messenger platform,
I want users to be able to provide location by using search.
It's working as expected in mobile app of the messenger as it's showing search option. But in the desktop version of the messenger, search option is not showing in location widget.
I wanted to ask that is it expected behavior or I'm missing out something.
Also in browser console, it's showing some error:
ErrorUtils caught an error:
"navigator.permissions.query(...).then(...).done is not a function".
Subsequent errors won't be logged;
see https://fburl.com/debugjs.ja # qtaMy7UNoCv.js:47.
Here's what I've tried so far:
def send_location_with_quick_reply(self, recipient_id, message, quick_replies):
url = self.get_message_url()
payload = {
"recipient":{
"id":recipient_id
},
"message":{
"text": message,
"quick_replies":[{
"content_type": "location"
}]
}
}
# _do_post will hit the send_message API of `Messenger`.
return self._do_post(url, payload)
And here's the response I'm getting after the user chooses the location:
{
"object": "page",
"entry": [{
"id": "128922990987384",
"time": 1505890084176,
"messaging": [{
"sender": {
"id": "1456347437763847"
},
"recipient": {
"id": "128922990987384"
},
"timestamp": 1505890084065,
"message": {
"mid": "mid.$cAAAvskrTvY9kz1Bs4Vengsjpb9L_",
"seq": 2366,
"attachments": [{
"title": "User's Location",
"url": "https:\\/\\/l.facebook.com\\/l.php?u=https\\u00253A\\u00252F\\u00252Fwww.bing.com\\u00252Fmaps\\u00252Fdefault.aspx\\u00253Fv\\u00253D2\\u002526pc\\u00253DFACEBK\\u002526mid\\u00253D8100\\u002526where1\\u00253D12.9703749\\u0025252C\\u00252B77.6361206\\u002526FORM\\u00253DFBKPL1\\u002526mkt\\u00253Den-US&h=ATNsjbke0tPFGIFpCq4MA5l1W6wmiwp0cTfUZNXSSbMDHxygEM4GrVlZmtaebsN4elliFhMSJNmIFwQgn-p_fxnF2hW0VdKTj2z_0hsWnH4dlLZGdQ&s=1&enc=AZN9DwrutbtXSfRAdxQf4bzFSMSO3zujAb0LBOgUt9mz16ZnDn7CSZDBLmnISjfAMbLG6b6H6hn9a3KCb6wOo7dn",
"type": "location",
"payload": {
"coordinates": {
"lat": 12.9703749,
"long": 77.6361206
}
}
}]
}
}]
}]
}
I am using python and drf to integrate with messenger platform.
Yes, this is expected behavior currently.
I'm using the paypal-python-sdk.
Currently, I'm redirecting the user to paypal where they log in, click confirm, and are redirected back to my site. No issues there. However, I have no idea how to get the authorization id so I can capture the amount authorized (or smaller). According to the docs its supposed to exist under related_resources but the list is always empty.
Will authorizations completed by logging into paypal return an authorization id?
Clarification: I know I can execute the payment with the payment_id. However, executing the payment is out of the question because I must be able to capture less than authorized.
request = {
"intent": "authorize",
"redirect_urls": {
"return_url": PAYPAL_RETURN_URL,
"cancel_url": PAYPAL_CANCEL_URL
},
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"total": str(self.order.total),
"currency": "USD"
},
"description": "Lorem lipsum"
}]
}
payment = Payment(request, api=self._connection())
I've been playing around with the Facebook API for a bit now, and I think I got it working quite well, however, when fetching my friends list I bump into a limit of 270 (271?) items returned with a paging key in the json data.
Naturally I try to iterate threw the next page in the paging key, however, the array returned from the next page is empty, it contains a next and previous key but no actual data, anyone know what's wrong?
Tried it straight in the browser just to ignore all programming errors and it's the same there as it is in the code:
https://graph.facebook.com/me/friends?access_token=[ACCESS_TOKEN]&limit=5000
I've also tried with &offset=269 etc, nothing really works, here's the output:
{
"data": [
{
"name": "Person A",
"id": "..."
},
{
"name": "Person B",
"id": "..."
},
{
"name": "Person C",
"id": "..."
}
],
"paging": {
"next": "https://graph.facebook.com/me/friends?limit=5000&offset=5268&value=1&access_token=[ACCESS_TOKEN]&__after_id=[Person C ID]",
"previous": " Previous URL ... "
}
}
When trying this URL in the browser (or via code), I get this:
{
"data": [
],
"paging": {
"previous": "https://graph.facebook.com/me/friends?limit=5000&offset=268&value=1&access_token=[ACCESS_TOKEN]"
}
}
Why is this and how do you go about fixing it?
Appreciate all the help i can get, thank you!
Edit: I have 284 friends, so there should be 10+ on the "next" paging.
(Programming done in Python via the "Official Python SDK" (modified to handle paging)
Maybe it's cos you might only have 270 (271) friends? Unless you are sure you have more friends...
If you have more than 270 friends. There could be two other reasons:
Those 14 users have prevented apps from accessing their data via the API
Facebook has cached your friend's list and you need to wait for the cache to be updated.