Currently writing my first bot using pyTelegramBotAPI. I want to disable link previews on certain messages. How do I do this?
It looks like there is an disable_web_page_preview parameter on the sendMessage method.
tb = telebot.TeleBot(TOKEN)
tb.send_message(123456, "Hi <link>", disable_web_page_preview=True)
Original code;
def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None,
parse_mode=None, disable_notification=None):
Try using link_preview/disable_web_page_preview parameter.
client.send_message('chat_name', '[link](example.com)', parse_mode = "Markdown", link_preview=False)
To me this works:
client.send_message(chat_name, msg, link_preview=False)
(Python 3.8, Telethon 1.24)
Related
Hi stalkers
Is there a way to access a site's data directly?
I need it for my code :
#commands.command(aliases = ['isitsafe','issafe','scanlink'])
async def isthissafe(self, ctx, link: str):
try:
link = 'https://transparencyreport.google.com/safe-browsing/search?url='+ link.replace('/','%2F')
embed=discord.Embed(
color = discord.Color.dark_red(),
title = '',
description = f"[Transparency Report verification]({link})")
await self.emb(embed, ctx.author.name, 'https://cwatch.comodo.com/images-new/check-my-site-security.png')
await ctx.send(embed=embed)
except:
await ctx.send('An error has occured')
print('\nERROR')
Basically I made, a command which should tell if a link is safe or not, I did it using google's verification report site, but.. the problem is I only reformatted the link so the bot sens it in an embed and you access it from there.
My question is, now that you understood what I need, is there some way in which I could directly let the bot output the message from the website that indicates if the site is malicious/safe ??
Please help me.
I provided an image as well with the message I want to get from the site.
You might want to try scraping the site with bs4, or just look for the string "No unsafe content found". However, it looks like google populates the field based on a request.
Your best bet would be to use transparencyreport.google.com/transparencyreport/api/v3/safebrowsing/status?site=SITE_HERE. It returns a JSON response, but I don't understand it, so play around and figure out what the keys mean
I'm creating a Telegram Bot and I need to get file_id.for example, photos.
For example:
"AgACAgIAAx0CW7VwqQAD3GE80mUSC6AbGV2lcHFzI5J3me7zAAJwtTEbkWJISbKzPMDueHfrAQADAgADeAADIAQ"
Is there such a possibility and how can I do it?
If you need more information, ask. Thank you!
Telethon documentation shows what attributes Document and Photo have.
So you can use the following code:
#client.on(events.NewMessage())
async def downloader(event):
file = event.document or event.photo
file_id = file.id
I'm trying to send a message from Symphony using Python.
https://developers.symphony.com/restapi/reference#create-message-v4
I found this page but I don't really know how to use it ( There's a cURL and a post url .. ) and I don't understand how I can use requests in this context ( still a beginner in API ).
Can someone help me to figure out how I can use this page to send a message from Python.
Thank you
You have to pass some required things in headers and use multipart/from-data content-type.
If you know about the postman then first with that and pass required headers.
files ={"message":"<messageML>Hello world!</messageML>"}
headers={
"sessionToken": "SESSION_TOKEN",
"keyManagerToken": "KEY_MANAGER_TOKEN"
}
requests.post("https://YOUR-AGENT-URL.symphony.com/agent/v4/stream/:sid/message/create", files=files,headers=headers)
https://github.com/finos/symphony-bdk-python/blob/main/examples has alot of examples on how to use symphony sdk. From python you don't want to use the api. This is the simple code to send a message from a bot. If you do not have a bot set up yet, follow https://docs.developers.symphony.com/building-bots-on-symphony/configuration/configure-your-bot-for-bdk-2.0-for-python NOTE you will need an admin user to follow these steps.
from symphony.bdk.core.config.loader import BdkConfigLoader
from symphony.bdk.core.symphony_bdk import SymphonyBdk
config = BdkConfigLoader.load_from_file("config.yaml")
async with SymphonyBdk(config) as bdk:
streams = bdk.streams()
messages = bdk.messages()
user_id = 123 # this can be found by clicking on a profile and copy profile link eg symphony://?userId=31123123123
stream = await streams.create_im_or_mim([user_id])
await messages.send_message(stream.id, f"<messageML>Message you want to send</messageML>")
I am writing a telegram bot in Python. I want to send messages with bold letters. I tried to inclose message inside both * and **, but it does not solve the problem.
Is there a function for mark up or HTML formatting or a way to do it?
You should use:
bot.send_message(chat_id=chat_id, text="*bold* Example message",
parse_mode=telegram.ParseMode.MARKDOWN)
Or:
bot.send_message(chat_id=chat_id, text='<b>Example message</b>',
parse_mode=telegram.ParseMode.HTML)
More info at:
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets#message-formatting-bold-italic-code-
This is a little bit late. But i hope to be helpful for others:
import telepot
token = 'xxxxxxxxxxxxxxx' # Your telegram token .
receiver_id = yyyyyyyy # Bot id, you can get this by using the next link :
https://api.telegram.org/bot<TOKEN>/getUpdates. Note that you should
replace <TOKEN> with your token.
bot = telepot.Bot(token)
message = "*YOUR MESSAGE YOU WENT TO SEND.*" #Any characters between ** will be
send in bold format.
bot.sendMessage(receiver_id, message , parse_mode= 'Markdown' )
#!/usr/bin/env python3
#-*- encoding: utf-8 -*-
from apikey import tgbottoken,authedchat
from telebot import types
import telebot,logging
bot =telebot.TeleBot(tgbottoken)
telebot.logger.setLevel(logging.DEBUG)
def extract_arg(arg):
return arg.split()[1:]
#bot.message_handler(commands=['newmail'])
def mailwithsg(msg):
cid = msg.chat.id
sendto = types.ForceReply(selective=False)
bot.send_message(cid, "Send me another word:", reply_markup=sendto)
bot.polling(none_stop=True)
after I use the methods and send a reply markup message, how should I get user's reply text (like user feedback)? which method should I use?
I now use pyTelegramBotAPI as a Python Wrapper.
It will reply a normal message.
Only Inline Keyboard should use CallBackQuery to handle it.
So that just use message_id to identify all messages and do what you want.
use my method from php - i think you can translate it to python;
switch($reply_to_message_text)
case 'Send me another word:':
$usersreply = $message ;
$this->db->addfeedback($user_id,$usersreply)
--------->here you can send some text to user and say Thanks)