I use this code
msg = await client.get_messages('me', limit=1, offset_id=0)
But print(msg) not show to me file_id like bots:
BQACAgQAAxkBAAK9_F8sa5j8iJQ845yxMdgYieRXRQwpAALrBwACzo2RU...
How I can get file_id for medias?
client.get_messages returns a list of Message. Your print(msg) will print this entire list. If you only want the Message.file (and within that the File.id), you should access that field:
messages = await client.get_messages(...)
print(messages[0].file.id)
Note that only bots can use this file ID to send it at a later time, and you don't need it to download the file at all.
Note that this file ID may not be valid forever.
Related
I used the below link.
https://api.roblox.com/users/**$UserID**/onlinestatus
for example:
https://api.roblox.com/users/543226965/onlinestatus
I have been receiving an error message from last time. The error message is given below.
{"errors":[{"code":404,"message":"NotFound"}]}
I heard the roblox API have been changed, but I can not find the right solutions, so I will be grateful for any answer.
Thanks.
It appears that you're trying to access the user's online status. As of right now, you can access this information by querying https://api.roblox.com/users/<user_id>, which returns a JSON object. Looking up IsOnline in the dictionary should return what you're trying to get
Here's an example I coded in Python:
import requests
res = requests.get(url='https://api.roblox.com/users/543226965')
res = res.json()
print(res['IsOnline'])
>>> True/False
This is my code to unban a user by replying to a message previously left by the user in the bot. But I also want to implement the /unban id command to be able to unban a user by their id. But I don't know how to do it. Please, help.
#bot.message_handler(commands=["unban"], func=Filters.is_answer)
def unblock(message):
user_id = (
Message.select()
.where(Message.id == message.reply_to_message.message_id)
.get()
.from_
)
try:
Block.select().where(Block.user_id == user_id).get().delete_instance()
bot.send_message(user_id, "you have been unbanned"),
except Block.DoesNotExist:
pass
bot.send_message(
message.chat.id, ("{user_id} has been unbanned").format(user_id=user_id)
)
I thought to just read the entire contents of the /unban command through message.text, but I didn’t see any errors, but the command stopped working
I am trying to pass a value inside below payload, I am able to get the value of it from the print but same is not accessible inside the payload, It prints the #(config.Secondary_ED) as the output.
The config.Secondary_ED contains an ip address. It works fine when I give ip address manually.
And print config.Secondary_ED
And request {"agent-forwarding":true,"configuration-data":"{\"service-host\":\"#(config.Secondary_ED)\",\"service-port\":\"8443\",\"user\":\"restdispatcher\",\"protocol\":\"vosrestdispatcher:rest\"}","configuration-template":null,"description":"Change Guardian Default Event Destination sk-12sp5","display-name":"sk-12sp5","ev-prototype-id":"1","forwarding-queries":[""],"id":1,"is-default":true,"is-indelible":true,"method":"vosrestdispatcher:rest","model":"REST Dispatcher","server-fordwarding":false}
When method PUT
Working Payload
#And print config.Secondary_ED
And request {"agent-forwarding":true,"configuration-data":"{\"service-host\":\"1.1.1.1\",\"service-port\":\"8443\",\"user\":\"restdispatcher\",\"protocol\":\"vosrestdispatcher:rest\"}","configuration-template":null,"description":"Change Guardian Default Event Destination sk-12sp5","display-name":"sk-12sp5","ev-prototype-id":"1","forwarding-queries":[""],"id":1,"is-default":true,"is-indelible":true,"method":"vosrestdispatcher:rest","model":"REST Dispatcher","server-fordwarding":false}
**Secondary_ED is stored in a json file called config.js
I have used # many times to get the value but same doesn't work in this case.
Please suggest what did I miss here.
Appreciate your help.
Please notice that the value of configuration-data is a string, not JSON object. Ask a friend who knows JS if this is not clear.
You can try this (note the usage of string):
* string configData = { 'service-host': '#(config.Secondary_ED)' }
* request { foo: '#configData' }
Or just use JS string concatenation (this is just a guess, please figure out what works for you, but you get the idea.
* def configData = '"{\\"service-host\\":\\"' + config.Secondary_ED + '\\"'
I am using Bitbucket API to retrieve different information. However I am looking to do a request that retrieves the latest commit for a repository. I initially thought it would be done like this:
https://bitbucket.org/!api/2.0/repositories/xxxx/xxxx/commits?limit=1
This just showed all the commits as normal but I want to show the most recent one. From looking through the API documentation I can't find anything that shows about limiting the number of commits to show. So was wondering if anyone could point me in the right direction?
Okay this wasn't straight forward either and I spent a couple of hours looking for how to do this myself. It ended up being easy if not unfortunate. Simply put the available API will not return just a target commit (like the latest). You have do parse it yourself. The following api:
"https://api.bitbucket.org/2.0/repositories/<project>/<repo>/commits/<branch>?limit=1"
Will still return ALL the commits for that particular branch BUT in order. So you can simply just grab the first result on the first page that is returned and that's the most recent commit for that branch. Here is a basic python example:
import os
import requests
import json
headers = {"Content-Type": "application/json"}
USER = ""
PASS = ""
def get_bitbucket_credentials():
global USER, PASS
USER = "<user>"
PASS = "<pass>"
def get_commits(project, repo, branch):
return json.loads(call_url("https://api.bitbucket.org/2.0/repositories/%s/%s/commits/%s?limit=1" % (project, repo, branch)))
def get_modified_files(url):
data = json.loads(call_url(url))
file_paths = []
for value in data["values"]:
file_paths.append(value["new"]["path"])
return file_paths
def call_url(url):
global USER, PASS
response = requests.get(url, auth=(USER, PASS), headers=headers)
if response.status_code == requests.codes.ok:
return response.text
return ""
if __name__ == "__main__":
get_bitbucket_credentials()
data = get_commits("<project>","<repo>","<branch>")
for item in data["values"]:
print("Author Of Commit: "+item["author"]["raw"])
print("Commit Message: "+item["rendered"]["message"]["raw"])
print("List of Files Changed:")
print(get_modified_files(item["links"]["diff"]["href"].replace("/diff/","/diffstat/")))
break
You can run the above example:
python3 mysavedfile.py
and that will output like:
Author Of Commit: Persons Name <personemail#email.com>
Commit Message: my commit message
List of Files Changed:
['file1.yaml','file2.yaml']
There a simple way to do it, using Bitbucket pagination mechanism.
Like so:
https://bitbucket.org/!api/2.0/repositories/xxxx/xxxx/commits?pagelen=1
Normally you'll need to specify the page number, "page=1", but the default is 1 so...
I want my bot to send special sticker. I got it ID in logs after sending it to bot.
file_id "CAADAgADOQADfyesDlKEqOOd72VKAg"
This is what getUpdates give me
But if I try to send it, for example:
https://api.telegram.org/bot<token>/sendSticker?chat_id=<id>&file_id=CAADAgADOQADfyesDlKEqOOd72VKAg
It responds"Bad Request: there is no sticker in the request". This is the code and it obviously does nothing:
def stickinmyass(bot, update):
bot.send_sticker(chat_id=update.message.chat_id, file_id='CAADAgADOQADfyesDlKEqOOd72VKAg')
stickyass = MessageHandler(Filters.sticker, stickinmyass)
dispatcher.add_handler(stickyass)
j = updater.job_queue
The file_id needs to be passed as the sticker parameter for the sendSticker method.
https://api.telegram.org/bot<token>/sendSticker?chat_id=<id>&sticker=CAADAgADOQADfyesDlKEqOOd72VKAg
or
bot.send_sticker(chat_id=update.message.chat_id, sticker='CAADAgADOQADfyesDlKEqOOd72VKAg')