I want to create two telegram bots on one adress https://example.com
this is working with webhooks, but i can't identify from which bot request came.
This is what i recieve from bot 1:
{
"update_id": 610779399,
"message": {
"message_id": 58,
"from": {
"id": 299470913,
"is_bot": false,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"language_code": "en"
},
"chat": {
"id": 299470913,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"type": "private"
},
"date": 1664720338,
"text": "this message is from bot 1"
}
}
This is what i recieve from Bot 2:
{
"update_id": 66917787,
"message": {
"message_id": 37910,
"from": {
"id": 299470913,
"is_bot": false,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"language_code": "en"
},
"chat": {
"id": 299470913,
"first_name": "my_first_name",
"last_name": "my_last_name",
"username": "my_user_name",
"type": "private"
},
"date": 1664720333,
"text": "this is from bot 2"
}
}
Responses looks identical, is it even possible to identify from which bot request came?
When setting up the webhook using setWebhook API method, you can set secret_token parameter, which will specify value of X-Telegram-Bot-Api-Secret-Token header in every request sent to your webhook.
Secret token is usually used for security purposes, to make sure that the requests sent to your webhook are really coming from Telegram (and not from some malicious actor). If you use different secret tokens for two different bots, you can also use these tokens to specify from which bot the request was sent.
Related
I'm trying to make confirmation slack button while running slash command. e.g. I run slash-command (/test) it sends the POST request to my python app which sends back 2 buttons (Confirm, Cancel). User presses one of the buttons slack triggers an action and sends another POST request to my app. All is working fine before this step - I cannot handle the data from 2nd POST request correctly.
In the Slack documentation I found this:
When an action is invoked, a request will be sent to the app's Request URL as configured above; the request body will contain a payload parameter that your app should parse for JSON.
When I do
data=json.loads(request.form["payload"])
return jsonify(data)
I get
{
"action_ts": "XXXX",
"actions": [
{
"name": "confirm",
"type": "button",
"value": "confirm"
}
],
"attachment_id": "X",
"callback_id": "XXXX",
"channel": {
"id": "XXXX",
"name": "XXXX"
},
"is_app_unfurl": false,
"message_ts": "XXXX",
"response_url": "XXXX",
"team": {
"domain": "XXXX",
"id": "XXXX"
},
"token": "XXXX",
"trigger_id": "XXXX",
"type": "interactive_message",
"user": {
"id": "XXXX",
"name": "XXXX"
}
}
After when I call
data=json.loads(request.form["payload"])
action=data["actions"]
return jsonify(action)
I get
[
{
"name": "confirm",
"type": "button",
"value": "confirm"
}
]
Now when I'm trying to get value of "name" with action["name"] I receive the error
TypeError: list indices must be integers or slices, not str
I tried json.dumps(action) and json.dumps(action["name"]) neither of them worked.
How to read that values? I need to check value of name and then do the rest with it.
[
{
"name": "confirm",
"type": "button",
"value": "confirm"
}
]
is a list containing one element - the dictionary. Access the name like data["actions"][0]["name"]
I would like to add a share button for social media. I've got the Slack workflow buttons working, but I'd like those receiving the message payload to be able to share what they're receiving. Here's what I've got so far.
def post_summary_to_slack(self):
data = str(
{'text': self.summary_printout,
'attachments': [
{
"fallback": "Was this a good use of time and money?",
"title": "Was this a good use of time and money?",
"callback_id": "meetings_survey",
"color": "#800080",
"attachment_type": "default",
"actions": [
{
"name": "yes",
"text": "Yes",
"type": "button",
"value": "yes"
},
{
"name": "no",
"text": "No",
"type": "button",
"value": "no"
},
{
"name": "maybe",
"text": "I'm Not Sure",
"type": "button",
"value": "maybe"
},
/* maybe here:*/
{
"name": "twitter",
"text": "Tweet",
"type": "button",
"value": "Here are the results from the latest analysis"
}
]
}
]
}
)
url = self.SLACK_HOOK
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
f.close()
Has anybody tried something like this? Thanks for the help!
Sure you can do that. However, Slack does not provide a Twitter share button out-of-the-box, so your script will need to implement that functionality. So your Twitter share button will call your script (like any other message button) and your script will need to forward the message contents to Twitter by calling the correct Twitter APIs etc.
I am in the process of migrating my Parse push notification data to CleverTap. The problem that I am having is that the documentation is not very good about it and the examples that they give don't cover push notifications.
Anyone have an example of how to send pushes with CleverTap API using Python or at least evidence that this is possible?
The documentation now covers how to migrate your Parse installations to CleverTap. For example, say we are creating a push notification to be sent to users subscribed to the "yankees" and "mets" channels.
curl -H "Content-Type:application/json"
-H "X-CleverTap-Account-ID: Your CleverTap Account ID"
-H "X-CleverTap-Passcode: Your CleverTap Account Passcode"
--data "#payload"
"https://api.clevertap.com/1/targets/create.json"
Payload
"name": "My API Campaign",
"where": {
"common_profile_prop": {
"profile_fields": [
{
"name": "channels",
"value": ["yankees", "mets"]
}
]
}
},
"content":{
"title": "Breaking News",
"body": "Yankees Win 5-4",
"platform_specific": {
"ios": {
"deep_link": "example.com",
"sound_file": "example.caf",
"category": "reactive",
"badge_count": 1,
"key": "value_ios"
},
"android": {
"background_image": "http://example.jpg",
"default_sound": true,
"deep_link": "example.com",
"key": "value_android"
}
}
},
"devices": [
"android",
"ios",
],
"when": "now"
}
Response
{
"status": "success",
"id": 1457433898,
"estimates": {
"android": 90,
"ios": 300
}
}
Hope this helps. More documentation can be found here -
https://github.com/CleverTap/parse-migrate
This is my first time with paypal and I need some help to finish payment integration. I've already tried to contact the paypal support but with no success. Here is my question and I really hope to get some help.
Something very strange grinds my gears and I cannot find why this do that. It's about the user authorization, and specially about paypal json responses. I'm using python sdk but that doesn't matter in this case. Here is my input.
paypalrestsdk.configure({
'mode': 'sandbox',
'client_id': 'XXX',
'client_secret': 'XXX'
})
payment = paypalrestsdk.Payment({
"intent": "authorize",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://mysite/success",
"cancel_url": "http://mysite/cancel"
},
"transactions": [ {
"amount": {
"total": price,
"currency": "USD"
},
"description": title
}]
})
And everything is ОК, except that I doesn't receive an Authorization ID. Here is what I receive as response:
{
'redirect_urls':{
'cancel_url':'http://glamfame.com:8000/cancel',
'return_url':'http://glamfame.com:8000/success'
},
'update_time':'2014-04-08T13:54:22Z',
'state':'created',
'transactions':[
{
'amount':{
'currency':'USD',
'total':'123.00',
'details':{
'subtotal':'123.00'
}
},
'description':'fawfwa',
'related_resources':[{
'authorization':{
'valid_until':'2014-05-07T13:54:22Z',
'update_time':'2014-04-08T13:54:22Z',
'parent_payment':'PAY-54Y91315F8620142DKNB77DQ',
'create_time':'2014-04-08T13:54:22Z',
'links':[{
'method':'GET',
[link removed]
'rel':'parent_payment'
}]
}
}]
}],
'payer':{
'payer_info':{
'shipping_address':{
}
},
'payment_method':'paypal'
},
'id':'PAY-54Y91315F8620142DKNB77DQ',
'intent':'authorize',
'create_time':'2014-04-08T13:54:22Z',
'links':[{ POST, GET, REDIRECT methods with links
}]
And below is what I supposed to receive according their documentation.
{
"id": "2DC87612EK520411B",
"create_time": "2013-06-25T21:39:15Z",
"update_time": "2013-06-25T21:39:17Z",
"state": "authorized",
"amount": {
"total": "7.47",
"currency": "USD",
"details": {
"subtotal": "7.47"
}
},
"parent_payment": "PAY-36246664YD343335CKHFA4AY",
"valid_until": "2013-07-24T21:39:15Z",
"links": [
{
"href": [link removed]
"rel": "self",
"method": "GET"
},
{
"href": [link removed]
"rel": "capture",
"method": "POST"
},
{
"href": [link removed]
"rel": "void",
"method": "POST"
},
{
"href": [link removed]
"rel": "parent_payment",
"method": "GET"
}]
}
As you maybe already noticed, in the paypal response doesn't contain authorization id and void, and capture link. Can you please help me to find out the reason for this. Thank you in advance.
Best Regards,
Georgi
From the REST API documentation: With PayPal payments authorizations, PayPal initially provides HATEOAS links that are specific to PayPal payments including an approval_url and execute link. First get payment approval and execute the payment as you normally would do for a PayPal payment. Once you successfully execute on the payment authorization, PayPal responds with a new set of HATEOAS links, including a capture link that you use to capture the payment.
I am new to freebase. Might be a simple answer but I cant seem to understand the freebase API. I try to run a simple query using the command queryResult = freebase.mqlread(queryFB); and I get the error below. I haven't logged in to the API. I created an account which is a google account. My question is when I call freebase.login(username,password); what do I use? Google account details? I am also attaching my query.
Query:
{
"type": "/food/dish",
"id": dish,
"name": None,
"cuisine":
[{
"id": None,
"name": None,
"region_of_origin":
[{
"id": None,
"name": None,
"/location/location/contains":
[{
"id": None,
"name": city,
"type": "/location/citytown",
"limit": 20
}]
}],
"optional": "optional"
}],
"type_of_dish1":
[{
"id": None,
"name": None,
"optional": "optional"
}]
}
Error:
{
"error":
{
"errors":
[
{
"domain": "usageLimits",
"reason": "userRateLimitExceededUnreg",
"message": "User Rate Limit Exceeded. Please sign up",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "User Rate Limit Exceeded. Please sign up"
}
}
Sounds like you might be using an obsolete client library and/or API. The current API doesn't use a username/password pair, but rather an API key.
Try this. It will explain how to use api key for running MQL. You will need to get only the apikey for freebase. NO username or password is required.
https://developers.google.com/freebase/v1/mql-overview