Git Product home page Git Product logo

python-telegram-bot's Introduction

python-telegram-bot

This is a telegram bot written in python. It uses the CLI of telegram by vysheng to connect.

Note: There is a better bot

This python based bot was written when I did not know how to use lua (which is embedded in tg-cli) to extend tg-cli.

But user yagop came up with a better bot written in lua

I will be submitting my improvements to his repo. If you want to keep up with my own fork, check this out

Since Lua is a lovable language and sicne tg-cli can pass it structured arguments, I will be trying to develop pure Lua modules in the lua bot rather than continue developing in python in this bot here.

Also, currently the way this bot operates is by reading lines from tg-cli output and parsing who sent it, to which group, etc based on the colours of the output. This is very unreliable and buggy and therefore not the preferred way of doing things. Although it works now, it could break any time. So it is wiser to follow the Lua version.

If you still want to use this bot, continue reading.

Installation

Install and setup vysheng/tg

Install vysheng's tg cli

Run that and configure an account

./telegram -k tg-server.pub

Install dependencies

The twitter module requires Python Twitter Tools

sudo easy_install twitter
twitter authorize

Install BeautifulSoup and other python modules with easy_install

sudo easy_install BeautifulSoup

Download python-telegram-bot

Clone this repository by doing

git clone https://github.com/asdofindia/python-telegram-bot.git && cd python-telegram-bot

Configure python-telegram-bot

There are a few changes to be made to the source code before it can start working.

In bot.py, change pathtotg to the path to the vysheng's tg CLI In bot.py, in the twitter function, change groupeer to the telegram user to whom you want the bot to send a message when there's a new tweet. In bot.py, in the twitter function, change the follow array to the accounts you want to get updates from In wolfram.py, put an appid by signing up at wolfram developers

Disabling modules

If you don't want some of these modules, just remove them from the modules array in callmodule function If you want to disable twitter, just comment out all lines with 'twitbot' in it in the main function. If you want to disable robotic replies turn chattybot to False

Features

The features as of now are

  • can be invoked from within a group or a direct message
  • wiki "search terms" will return the first paragraph of the wikipedia article
  • google "search terms" will return a few google results
  • bot "question" will fetch the answer from wolfram alpha api
  • new twitter messages from your feed are automatically sent to the defined peer
  • talks random shit based on pandorabots web service thanks to chatterbotapi

Known Bugs

  • twitter module repeats tweets. This is more of a problem with the twitter python module rather than this code. Todo: prevent duplicate tweets using timestamp
  • chatting with oneself is buggy, I suppose. Not tested very much. No time :P

python-telegram-bot's People

Contributors

asdofindia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

python-telegram-bot's Issues

wiki.py Issue with empty <p> tags

If a page has something like:

    <p><br />
    </p>

the code

msg = ''.join(soup.p.findAll(text=True))

returns an empty string.
To avoid this you can use:

    for para in soup.findAll('p'):
        if not para.text == "":
            msg = msg + para.text

echobot.py gives IndexError: list index out of range

After inserting my token I did run the echobot.py

It gives me the following error

Traceback (most recent call last):
File "<pyshell#3>", line 1, in
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id
IndexError: list index out of range

What can I try to debug this?

UnicodeEncodeError: 'ascii' codec can't encode character

Hello,
Your bot are working great, many thanks. But sometimes I hit the following bug:

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 811, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 764, in run
self.__target(_self.__args, *self.__kwargs)
File "bot.py", line 178, in bot
AI(group,peer,message)
File "bot.py", line 91, in AI
msg(group,peer,reply)
File "bot.py", line 113, in msg
proc.stdin.write('msg '+peer.replace(' ','
')+' '+message+'\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 33: ordinal not in range(128)

Does this have to do with charset transformation?

sh: 1: expects/tgrecvmsg.xp: not found

I have this output when i ./start.sh.

sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found
sh: 1: expects/tgrecvmsg.xp: not found

I think the problem could be because there is a new version of tg on vysheng's repo, from where you forked https://github.com/vysheng/tg

Add auto split messages

My bot sending a very long messages, but there are limitation for message length (2048 symbols).
How to autosplit message and then send?

IndexError: list index out of range in chatterbotapi.py

Hello,
One more stability issue. I am getting a lot of those regularly:

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 811, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 764, in run
self.__target(_self.__args, *_self.__kwargs)
File "bot.py", line 178, in bot
AI(group,peer,message)
File "bot.py", line 84, in AI
reply=callmodule(message,peer)
File "bot.py", line 62, in callmodule
reply = botsessions[peer].think(message)
File ".../python-telegram-bot/chatterbotapi.py", line 58, in think
return self.think_thought(thought).text
File "/.../python-telegram-bot/chatterbotapi.py", line 152, in think_thought
response_thought.text = response_dom.getElementsByTagName('that')[0].childNodes[0].data.strip()
IndexError: list index out of range

I not sure if it is a issue on chatterbotapi.py or in bot.py, so I have opened this issue so you can take a look.

Long message

I can't send long messages.
How to autosplit messages?

bot.py just exists

Hello,
I am trying to use python-telegram-bot, but I am having issues on new telegram-cli.
I had to change the paths and added a '-cli' in program call.
But when I do python bot.py, nothing happens:

$python bot.py
Telegram-cli version 1.0.5, Copyright (C) 2013-2014 Vitaly Valtman
Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type show_license'. This is free software, and you are welcome to redistribute it under certain conditions; typeshow_license' for details.
*** No pubic keys found
$

it seems to me that the program just leave Telegram.
Any help will be appreciated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.