Difference beetween using pyTelegramBotAPI and Telegram Bot API - python

I'm new to python and telegram bot programming, and I have been programming a telegram bot using pyTelegramBotAPI because the tutorials I followed used it, but I can't find no information on the internet about a definition/description about pyTelegramBotAPI and why should I use it instead of Telegram Bot API.
Can someone help me with these questions? I literally couldn't find these information on the internet. Thanks

pyTelegramBotAPI is a python implementation of the Telegram Bot API.
You're not choosing to use pyTelegramBotAPI instead of the Telegram Bot API - rather you're choosing to use pyTelegramBotAPI for the Telegram Bot API. This is one of numerous Python implementations and Python is just one of many languages that implementations are written in. If you really want, you can operate a Telegram Bot using shell commands.
In general terms, an implementation of a HTTP-based API written in a particular language simplifies building your program by allowing you to specify your ID's and credentials, and then simply calling functions to get things done, instead of having to engineer every call and include the paramaters manually or repetitively. It also takes care of constructing the requests and passing the paramaters in a compatible format to the server, while it may also provide some additional parsing to the paramaters provided to the abstracted functions.
Reasons you may wish to use pyTelegramBotAPI:
You like the features and functionality of pyTelegramBotAPI. I.e. You're looking for a framework for a project like one of these
You want a Python implementation of the Telegram Bot API without having to build it from scratch yourself.
You want a fairly comprehensive and extensible implementation of the Telegram Bot API (true at the time of writing this)
The Documentation explains what you need to be aware of, and how certain aspects translate to the API. I.e, there's a paragraph explaining the convention of method names has been modified to more idiomatic Python;
Methods
All API methods are located in the TeleBot class. They are renamed to
follow common Python naming conventions. E.g. getMe is renamed to
get_me and sendMessage to send_message.
There's also a note about the renaming of from to from_user
Reasons you may not want to use pyTelegramBotAPI
As mentioned above, pyTelegramBotAPI is maintained and updated regularly at the time of writing this. However, there's never a guarantee that code written by someone else will always be maintained in either it's original form or forked off and taken in a new direction.
You may choose against using something like this if:
Python is unavailable in your environment
You require an extremely simple and lightweight use of a bot and could maintain it quicker by referring directly to the official Telegram API reference.
You are looking to integrate to another project using a different language.
You aren't confident in extending the the code to suit your requirements.

Related

How to add python code to Nodejs Express API?

I am creating a Express.js API that offers json data when request is received by an end-point.
for example- like this one, jokes api, weather api, etc
But I have some logics that I want to implement in python as there are some very good libraries like requests in python.
I have seen in many places that many softwares can be written in multiple languages, here
Demonstration (what I want to achieve):
I have an api called example.com
Someone made a get request to example.com/api/v1/category/json-data?quantity=4
Now, the app.get(example.com/api/v1/category/json-data?quantity=4) route in my code will be triggered and from there I want to call my python code that will do some job and finally what user wants will be sent back.
How can I achieve this?
What should my folder structure look like?
How to manage both python and npm dependencies together?
Please share any article, documentation or video I can refer.

Swagger and then flask or opposite

Swagger and then flask or opposite
Hello,
I'm starting a new poroject who need an API.
I 'm going with flask and swagger.
A simple question: should i start by defining the API with swagger and then generate the python code or the opposite.
Thank for your help.
There are solutions for both approaches:
If you end up preferring to define the API first, I would recommend connexion. You define OpenAPI (new name for Swagger) specification files, and then you do Python code accordingly. I would say that this is the best approach as you can guarantee that whatever code you write afterwards will conform to the specification, that you can provide to whoever wants it. Another advantage is not mixing up core concepts of your logic with the API specification.
Otherwise, flask-restplus does the trick. This is the most common (but not necessarily better) approach, where you write your Python code and the specification is then generated. This is the approach I usually follow in simple use cases.
For information i finally choose the openapi-generator tool that allow me to generate python server stub on Flask/connexion stack and my client lib for Android on top of okhttp.
https://github.com/OpenAPITools/openapi-generator
I was rather satisfied with this choice during my project.
To merge your server stub last version with older one you can dedicated a git branch for raw server stub generation and another one wich you fill with your own code. That way you won't lose your previous version with the code you add to the server stub.

Can I get a list of users that requested to follow me in my Instagram private account?

I'm using instabot in python.
I want to get a list of users that requested to follow me and accept some of them according to some conditions and stuff.
I have read the documentation and didn't find anything about this.
I just want to have the list somehow.
Not just through instabot.
So if u know another way to get the list, some kind of web scraping or by using another bot or even Instagram's native API, I will be happy to hear (read!) that.
I am not familiar with Instabot in Python, but you can use this as a reference https://github.com/mgp25/Instagram-API.
That library is written in PHP and able to do get your pending follower list, even to do actions such as reject or accept the follow request. I'm currently using that library and it's well maintained.
Hope that helps. :)
Install following library:
https://github.com/instagrambot/instabot
And use get_pending_follow_requests function to retrieve intended list.

Adding account and more user-friendly integration into Twitch bot

Lately, I've worked on a chat bot of my own for twitch.tv, connecting using the IRC channel and using a python script as well as logs from HexChat, my IRC client, to build my bot, which currently can give(upon query) the uptime of the channel, and statistics on emotes in the channel.
However, I have seen Moobot and Nightbot, 2 of the most popular chat bots on twitch, and was wondering how I could:
1) Turn this python script into something a streamer can authorize to be on their channel,
2) Hook up a GUI to this, or a series of text fields for the user to input their settings for the bot while it runs on their channel.
I have looked at previous questions on StackOverflow, looked on Google, and asked in the #twitch-api IRC channel on freenode, however none of these provided the answer, and the only bots I have seen that have this channel-bot integration and authorization are Moobot and Nightbot. Upon clicking "connect to twitch" on moobot's homepage, I can authorize it to use my account much like an oauth request, however I do not know how to set this up. I hope this will help others like me wanting to add some extra usability to their WIP Twitch Chat bot. Thanks!
Moobot: http://twitch.moobot.tv/
Nightbot: https://www.nightbot.tv/
Most of the "big" server-hosted bots consist of 4 major parts:
A database (SQL or NoSQL) holding all the settings etc.
A REST (or similar) API that is used to communicate between the individual parts
A web application for the frontend
A standalone bot for the backend
Keep in mind that this is alot of work to set up. I am currently working on a full rewrite of my bot, which I would share if it wasnt in a pre-alpha state.
Keep in mind that setting up these individual parts might require an experienced web developer. Here is some tips however:
Using python, Django is a great decision for a web application + API backend
As far as I know, there is no decent IRC library for python supporting IRC v3 so you might have to implement your own. Sample implementation of the message parser
Apart from that, see the Twitch.tv API documentation - this includes the Authentification workflow.
If you are looking for a locally-hosted bot, that's a completely different thing to deal with. There is a fair amount of those, some of which are open source too. I dont know any low-level ones, but maybe looking at Botnak, made by a friend of mine, answers some questions.

IRC bot functionalities

I'm learning Python and would like to start a small project. It seems that making IRC bots is a popular project amongst beginners so I thought I would implement one. Obviously, there are core functionalities like being able to connect to a server and join a channel but what are some good functionalities that are usually included in the bots? Thanks for your ideas.
Unless it's solely for the educational experience, you should really just use a framework for the core functionality.
That said, here's some of the things the bot in my home IRC channel does:
Choose one item from a list of options
Display a random entry from the Linux fortunes file
Display a random set of words from the Emacs spook file
Check every line from a user and display a quote from The Big Lebowski if it's sufficiently similar (this is probably a bit my-channel specific :) )
Check if a link has been mentioned before and say who/when (we all read the same RSS feeds and tend to duplicate links a lot)
Conduct a poll
Pull a given quote from our internal QDB
Check if a given link has been posted to Reddit, and give the corresponding Reddit thread link if so. If a Reddit link is posted, give the direct link instead
Track the last time a given nick was in the channel, and the last time they spoke
Queue a message for an offline nick that's automatically sent in-channel when they join
Use Google Translate to translate a given phrase
Post a given line to our channel's Twitter feed
Choose a random user and kick them (not the best idea depending on how unruly your channel is)
Pull the summary of a given term from Wikipedia and display it along with a link to the full article
Display information about any posted Youtube link (video title, length, submitter, votes, comments, etc.)
I'm also in the process of writing a bot in node.js. Here are some of my goals/functions:
map '#' command so the bot detects the last URI in message history and uses the w3 html validation service
setup a trivia game by invoking !ask, asks a question with 3 hints, have the ability to load custom questions based on category
get the weather with weather [zip/name]
hook up jseval command to evaluate javascript, same for python and perl and haskell
seen command that reports the last time the bot has "seen" a person online
translate command to translate X language string to Y language string
map dict to a dictionary service
map wik to wiki service
Again, this is an utterly personal suggestion, but I would really like to see eggdrop rewritten in Python.
Such a project could use Twisted to provide the base IRC interaction, but would then need to support add-on scripts.
This would be great for allowing easy IRC bot functionality to be built upon using python, instead of TCL, scripts.
That is very subjective and totally depends upon where the bot will be used. I'm sure others will have nice suggestions. But whatever you do, please do not query users arbitrarily. And do not spam the main chat periodically.
Make a google search to get a library that implements IRC protocol for you. That way you only need to add the features, those are already something enough to bother you.
Common functions:
Conduct a search from a wiki or google
Notify people on project/issue updates
Leave a message
Toy for spamming the channel
Pick a topic
Categorize messages
Search from channel logs

Categories

Resources