Basecamp - Get Attachments - Page 2 of results - basecamp

I am trying to return all the attachments in a project using the basecamp api call documented here:
https://github.com/basecamp/bcx-api/blob/master/sections/attachments.md
The Basecamp documentation says that you can do this in this way...
https://basecamp.com/1234567/api/v1/projects/1234567/attachments.json
Which will return the top 50 results. And which is does :)
But, I have more than 50 results.
So, the documentation says:
We will return 50 attachments per page. If the result set has 50 attachments, it's your responsibility to check the next page to see if there are any more attachments -- you do this by adding &page=2 to the query, then &page=3 and so on.
So, I have tried:
https://basecamp.com/1234567/api/v1/projects/1234567/attachments.json&page=2
But when I try this I get an error:
HTTP/1.1 415 Unsupported Media Type - Only application/json requests are accepted. Check out 'No XML, just JSON' on https://github.com/37signals/bcx-api
Am I reading the instructions wrong? Sure that call should work?
Any help would be greatly appreciated.

Apologies.
I should have spotted it... the documentation says "&" when it should say "?"
The call should be
https://basecamp.com/1234567/api/v1/projects/1234567/attachments.json?page=2

Related

pyTelegramBotAPI inline google search engine

#bot.inline_handler(func=lambda query: len(query.query) > 0)
def query_text(query):
sleep(6)
text=query.query
html=requests.get(f'https://google.com/search?q={text}')
# print(html.status_code)
open('index.html','w', encoding='utf-8').write(html.text)
soup=BeautifulSoup(html.text, 'html.parser').find_all('div',{"class":"***********"})
for i in soup:
fk.append(types.InlineQueryResultArticle(id=str(len(fk)), title=f"{i.find('h3').get_text()}",description=f"{i.find('div',{'class':'**********'}).get_text()}",input_message_content=types.InputTextMessageContent(message_text=i.find('a').get('href').replace('/url?q=','https://google.com/url?q=')),hide_url=True,url=i.find('a').get('href').replace('/url?q=','https://google.com/url?q='),thumb_url='https://w7.pngwing.com/pngs/338/520/png-transparent-g-suite-google-play-google-logo-google-text-logo-cloud-computing.png', thumb_width=30, thumb_height=30))
print(i.find('a').get('href').replace('/url?q=','')+'\n')
sleep(2)
bot.answer_inline_query(query.id, fk)
When I write #bot google request
Bot takes it as g go goo google
What is causing the error
"A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: query is too old and response timeout expired or query ID is invalid"
How to make text input timeout so that it doesn't respond to every letter?
I think, the error resides in your way of parsing data. It takes at least 8 seconds (based on sleeps) just to get to the answer method. Telegram inline queries have very few seconds until they are considered old, so, it is better to process data after you call bot.answer_inline_query() and then send it to user using bot.send_message()
I am not certain how it works with async code though.
If you find another solution, please let me know :)

Clear "pending_update_count" in Telegram Bot

I want to clear all pending_update_count in my bot!
The output of below command :
https://api.telegram.org/botxxxxxxxxxxxxxxxx/getWebhookInfo
Obviously I replaced the real API token with xxx
is this :
{
"ok":true,"result":
{
"url":"",
"has_custom_certificate":false,
"pending_update_count":5154
}
}
As you can see, I have 5154 unread updates til now!! ( I'm pretty sure this pending updates are errors! Because no one uses this Bot! It's just a test Bot)
By the way, this pending_update_count number are increasing so fast!
Now that I'm writing this post the number increased 51 and reached to 5205 !
I just want to clear this pending updates.
I'm pretty sure this Bot have been stuck in an infinite loop!
Is there any way to get rid of it?
P.S:
I also cleared the webhook url. But nothing changed!
UPDATE:
The output of getWebhookInfo is this :
{
"ok":true,
"result":{
"url":"https://somewhere.com/telegram/webhook",
"has_custom_certificate":false,
"pending_update_count":23,
"last_error_date":1482910173,
"last_error_message":"Wrong response from the webhook: 500 Internal Server Error",
"max_connections":40
}
}
Why I get Wrong response from the webhook: 500 Internal Server Error ?
I think you have two options:
set webhook that do nothing, just say 200 OK to telegram's servers. Telegram wiil send all updates to this url and the queque will be cleared.
disable webhook and after it get updates by using getUpdates method, after it, turn on webhook again
Update:
Problem with webhook on your side. You can try to emulate telegram's POST query on your URL.
It can be something like this:
{"message_id":1,"from":{"id":1,"first_name":"FirstName","last_name":"LastName","username":"username"},"chat":{"id":1,"first_name":"FirstName","last_name":"LastName","username":"username","type":"private"},"date":1460957457,"text":"test message"}
You can send this text as a POST query body with PostMan for example, and after it try to debug your backend.
For anyone looking at this in 2020 and beyond, the Telegram API now supports clearing the pending messages via a drop_pending_updates parameter in both setWebhook and deleteWebhook, as per the API documentation.
Just add return 1; at the end of your hook method.
Update:
Commonly this happens because of queries delay with the database.
I solved is like this
POST tg.api/bottoken/setWebhook to emtpy "url"
POST tg.api/bottoken/getUpdates
POST tg.api/bottoken/getUpdates with "offset" last update_id appeared before
doing this serveral times
POST tg.api/bottoken/getWebhookInfo
had a look if all away.
POST tg.api/bottoken/setWebhook with filled "url"
If you are using webhook, you can follow these steps
On your web browser, enter the following url with your right value of bot
https://api.telegram.org/bot/getWebhookInf
You will get a result like this on your screen
{"ok":true,"result":{"url":"url_value",...}}
On the displayed result, copy the entire url_value without quotes and replace it on this second url
https://api.telegram.org/bot/setWebhook?url=url_value&drop_pending_updates=True
Enter the second url with right bot and url_value in your web browser then press ENTER
Done!
i solve it by Change file access permissions file - set permissions file to 755
and second increase memory limit in php.ini file
A quick&dirty way is to get a temporary webhook here: https://webhook.site/ and
set your webhook to that (it will answer with a HTTP/200 code everytime, reseting your pending messages to zero)
I faced the same issue for my tele bot after user edited existing message. My bot receives update with editedMessage continuously, but update.hasMessage() was empty. As a result number of updates rocketly increased and my bot stack.
I solved this issue by adding handling for use case when message is missing - send 200 code:
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
update = MAPPER.readValue(event.getBody(), Update.class);
if (!update.hasMessage()) {
return new APIGatewayProxyResponseEvent()
.withStatusCode(200) // -> !!!!!! return code 200
.withBody("message is missing")
.withIsBase64Encoded(false);
}
... ... ...

How can I send more information via GET method? in VALENCE

i need help with Valence portal.
I open the app with direct link
here:
http://192.168.1.1:7040?display=desktop&app=1001
but I need more data on this, PE: 'CODUSER' but if I put &coduser=1 doesn't work
http://192.168.1.1:7040?display=desktop&app=1001&coduser=1
I extecute an alert and this is the result to read the URL:
http://192.168.1.1:7040/desktop/examples/P01/index.html?app=1001&key=xxxxxxx&lang=en
URL doesn't contains the "coduser".
How can I send more information via GET method?
Thanks, Ivan.
I found a solution to my problem. Not is the best solution but is an aceptable solution, if any knows other, tell me, please.
My Solution:
I created a new Hook.js. on this file can read a current url (here read all url, 'coduser' included).
on the new Hook:
cod=foundParameterURL('codUser');//personal function, include current URL (location.href)
Ext.util.Cookies.set("coduser",cod);
later on the app, read the Cookie:
var cod = Ext.util.Cookies.get("coduser");
and continue with normality
If any knows as send information Hook.js to app tell me please.
thanks for all, Ivan.

Post a text request in Casablanca (C++ REST SDK)

I am writing a client side code in Visual C++ 2012 using C++ Rest SDK (codename "Casablanca").
I have a client created and wish to POST a text string to the server. However, when I send the following code, it is compiling but not sending sending the request.
When I remove everything after "methods::POST" and send a blank post request, then it is sent and received by the server.
Can you please guide me where the problem is. The documentation related to this function is available on Casablanca Documentation.
pplx::task<http_response>resp = client.request(methods::POST,L"",L"This is the random text that I wish to send", L"text/plain");
I think the usage you give here looks correct.
Is your Casablanca the latest version ? Please check that out from here : http://casablanca.codeplex.com/
If you are sure your measurement is accurate, you may want to create a minimal repro and file a bug here : http://casablanca.codeplex.com/workitem/list/basic
I was having a similar problem, all my POSTs was arriving in blank on server , after a few hours work above it, i found a possible solution.
I changed the default content type to application/x-www-form-urlencoded and I started to pass the values like this Example data=text1&data2=text2
client.request(methods::POST,L"",L"data=text1&data2=text2", L"application/x-www-form-urlencoded");
The body parameter must be a json::value.
I cannot comment yet so I have to put my thoughts in an answer. I solved this problem like this: There is an overload of the request method that takes as a parameter the content type so that you do not have to change the code.
m_client->request(methods::POST, L"/statuses/update.json?" + url_encode(data),L"",L"application/x-www-form-urlencoded");
Obviously you would have to implement the url_encode method but that is not difficult. There is a pretty good implementation in "Cassablanca". A search on this site will alos turn up some good examples.

Gmail IMAP via php ouath2 Zend_Mail_Protocol_Imap - getting the X-GM-THRID

I'm accessing GMail via IMAP using OAuth2 authentication and Zend_Mail_Protocol_Imap.
It all works great.
What I need to do is present emails in thread form just like the GMail interface. Google make this really easy because they have an X-GM-THRID header that links a conversation with a 64-bit unsigned integer.
My problem is: when presented with a single email, how do I find out what X-GM-THRID it belongs to?
First off Google says that there is a server extension X-GM-EXT-1 which is active. You can check it is there using the CAPABILITY command (and I have).
All the information suggests that if this is active then the X-GM-THRID will simply be returned as a header, but it isn't.
Perhaps I need to ask Google to return it via the fetch command. Google does describe a simple fetch process here:
https://developers.google.com/google-apps/gmail/imap_extensions
My code is sending TAG5 FETCH 3673 (FLAGS RFC822.HEADER X-GM-THRID) but the headers do not include an entry for X-GM-THRID.
I've even simplified it to TAG6 FETCH 3673 (X-GM-THRID) to be exactly as described in the google example. In this case no headers are returned.
I'm not massively familiar with IMAP commands and I'm not sure if Zend_Mail_Protocol_Imap is abstracting some handling which means this header is being removed.
But I do know that this is driving me mad.
Am I missing something? Is it not a header?
Okay, so it looks like it is not a header. It is an attribute in the IMAP command and response.
The standard fetch command sent by Zend_Mail_Protocol_Imap is "TAG5 FETCH 3673 (FLAGS RFC822.HEADER)"
The code that handles the response only expects to be dealing with 'FLAGS' and 'RFC822.HEADER'. It passes this information to a Zend_Mail_Message object which extends Zend_Mail_Part.
Zend_Mail_Part parses information about flag. It also parses the header.
The additional 'X-GM-THRID' attribute that I added does actually get a response. but since it is not passed back to Zend_Mail_Message there is no way for me to use it. It gets lost in the ether (at around line 171 of Zend_Mail_Storage_Imap in my Zend Library to be exact).
So I've hacked the core... Zend_Mail_Storage_Imap::getMessage now expects $data['X-GM-THRID'] and passes it to the constructor Zend_Mail_Part. And I now have a method Zend_Mail_Part::getXGmThrid which solves all my problems. I'll obviously refactor them into my own classes extending Zend_Mail_Storage_Imap and Zend_Mail_Part in the not too distant... but for now I know this works.

Resources