Coder Social home page Coder Social logo

telegram-twitter-forwarder-bot's Introduction

telegram-twitter-forwarder-bot

logo

Hello! This projects aims to make a Telegram bot that forwards Twitter updates to people, groups, channels, or whatever Telegram comes up with!

It was once hosted on Telegram as @TwitterForwarderBot which doesn't work anymore. There are a few other instances running around:

  • (add a Pull Request linking to your instance here!)

Credit where credit is due

This is based on former work:

So, big thanks to anyone who contributed on these projects! :D

How do I run this?

  1. clone this thing
  2. fill secrets.py (see next readme section)
  3. (optional) create your virtualenv, activate it, etc, e.g.:
    virtualenv -p python3 venv
    . venv/bin/activate
    
  4. pip install -r requirements.txt
  5. run it! python main.py

secrets.py?? what is that?

This bot requires a few tokens that identify it both on Twitter and Telegram. This configuration should be present on the secrets.py file.

There's a skeleton of that on example-secrets.py, start by copying it to secrets.py. The second one is the one you should change.

First, you'll need a Telegram Bot Token, you can get it via BotFather (more info here).

Also, setting this up will need an Application-only authentication token from Twitter (more info here). Optionally, you can provide a user access token and secret.

You can get this by creating a Twitter App here.

Bear in mind that if you don't have added a mobile phone to your Twitter account you'll get this:

You must add your mobile phone to your Twitter profile before creating an application. Please read https://support.twitter.com/articles/110250-adding-your-mobile-number-to-your-account-via-web for more information.

Get a consumer key, consumer secret, access token and access token secret (the latter two are optional), fill in your secrets.py, and then run the bot!

Setting up cronjob

contributed by @llg, thanks!

Make sure crontab user have write access to venv directory

  1. use examples/cron-run.sh script in cron: * * * * * cd /path/to/telegram-twitter-forwarder-bot && examples/cron-run.sh >> /dev/null 2>&1
  2. you can change time for checking to any you want

telegram-twitter-forwarder-bot's People

Contributors

cobular avatar dependabot[bot] avatar franciscod avatar jh0ker avatar krikunts avatar lgg avatar prihlop 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

telegram-twitter-forwarder-bot's Issues

Posting in Telegram Channel

Is there a solution so that the bot is able to post in channels? As long as the bot cant read messages so /sub is redundant?

would you please help me on installing the bot on an EC2?

Thank you very much for your code!
when i install it in an ubuntu@EC2 following the instruction, I got this error, Would you like to read it and give me some suggetion. Thank you!

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    from bot import TwitterForwarderBot, FetchAndSendTweetsJob
  File "/home/ubuntu/telegram-twitter-forwarder-bot/bot.py", line 9, in <module>
    from basebot import BaseBot, Job
  File "/home/ubuntu/telegram-twitter-forwarder-bot/basebot.py", line 98
    command, *args = text[1:].split()
             ^
SyntaxError: invalid syntax

tw_users is len 0 all the time

Can someone help me as i don't seem to be getting any updates through to my bot when i post a new tweet on my feed.
I am new to all this so help would be appreciated

A bug found

Hi
I am using Python 3.5 on Cent OS 6.

I faced the following error when trying to run it

$ python main.py
Traceback (most recent call last):
File "main.py", line 9, in
from bot import TwitterForwarderBot
File "/home/syko/telegram/telegram-twitter-forwarder-bot/bot.py", line 9, in
from models import TelegramChat, TwitterUser
File "/home/syko/telegram/telegram-twitter-forwarder-bot/models.py", line 90, in
t.create_table(fail_silently=True)
File "/usr/local/lib/python3.5/site-packages/peewee.py", line 5028, in create_table
if fail_silently and cls.table_exists():
File "/usr/local/lib/python3.5/site-packages/peewee.py", line 5024, in table_exists
return cls._meta.db_table in cls._meta.database.get_tables(**kwargs)
AttributeError: 'NoneType' object has no attribute 'get_tables'

Check for errors on /verify

in telegram message history:

image

while in logs:

2018-01-10 04:11:59,686 - TwitterForwarderBot - DEBUG - No new updates found.
2018-01-10 04:12:02,492 - TwitterForwarderBot - DEBUG - Getting updates: [434142446]
None
None
2018-01-10 04:12:03,170 - telegram.ext.dispatcher - ERROR - An uncaught error was raised while processing the update
Traceback (most recent call last):
  File "/home/webadmin/www/console/telegram/chat-crypto/telegram-twitter-forwarder-bot/venv/lib/python3.5/site-packages/telegram/ext/dispatcher.py", line 203, in process_update
    handler.handle_update(update, self)
  File "/home/webadmin/www/console/telegram/chat-crypto/telegram-twitter-forwarder-bot/venv/lib/python3.5/site-packages/telegram/ext/commandhandler.py", line 86, in handle_update
    return self.callback(dispatcher.bot, update, **optional_args)
  File "/home/webadmin/www/console/telegram/chat-crypto/telegram-twitter-forwarder-bot/util.py", line 14, in wrapper
    return f(bot, update, *args, **kwargs)
  File "/home/webadmin/www/console/telegram/chat-crypto/telegram-twitter-forwarder-bot/commands.py", line 268, in cmd_verify
    cmd_set_timezone(bot, update, [tz_name])
  File "/home/webadmin/www/console/telegram/chat-crypto/telegram-twitter-forwarder-bot/util.py", line 14, in wrapper
    return f(bot, update, *args, **kwargs)
  File "/home/webadmin/www/console/telegram/chat-crypto/telegram-twitter-forwarder-bot/commands.py", line 298, in cmd_set_timezone
    tz = timezone(tz_name)
  File "/home/webadmin/www/console/telegram/chat-crypto/telegram-twitter-forwarder-bot/venv/lib/python3.5/site-packages/pytz/__init__.py", line 173, in timezone
    if zone.upper() == 'UTC':
AttributeError: 'NoneType' object has no attribute 'upper'
2018-01-10 04:12:12,503 - TwitterForwarderBot - DEBUG - No new updates found.

AttributeError: 'NoneType' object has no attribute 'safe_create_index'

I'm getting this error on Debian in a virtualenvironment.

$ python main.py Traceback (most recent call last): File "main.py", line 9, in <module> from bot import TwitterForwarderBot File "/home/adem/twitterbot/bot.py", line 10, in <module> from models import TelegramChat, TwitterUser File "/home/adem/twitterbot/models.py", line 90, in <module> t.create_table(fail_silently=True) File "/home/adem/twitterbot/venv2/lib/python3.5/site-packages/peewee.py", line 5665, in create_table if safe and not cls._meta.database.safe_create_index \ AttributeError: 'NoneType' object has no attribute 'safe_create_index'

I don't know, what to do.

Sending media

It will be better if there is any media in tweet bot should send it with text message in that tweet as a caption of the media. Now images in tweets are sending as preview only

sometimes /auth doesn't work

/sub durov

Sorry, I didn't find username durov

Installed this script on my own server, all tokens were added to secrets

How to use it in Telegram Channel/Group

I am a rookie, an undergraduate student, and want to follow researchers, academicians, labs, universities, latest news from research etc in telegram because social media distracts me, even I have ADHD. Bot works on a Droplet, but not in Telegram, I couldn't. How can I add bot to my telegram group or channel?

it is done

Rename bot?

Hello,

Fantastic bot! We'd love to rename it to "Our Channel Name - Tweets", can we somehow rename the bot?

RTs images and website links are not showing

Hi there,

Is it normal that RT's images and links are not being shown? Brings often the messages fully out of context. Is there a way to add / improve that?

Thanks for your help!

Post full tweet to Telegram

Now that Twitter has increased the amount of characters in a tweet will it be possible to post the full tweet text to telegram without the url linking to the extended text.

Sourcing secrets.env doesn't work smoothly on Windows

Keep getting the following error

C:\Users\user\Downloads\telegram-twitter-forwarder-bot-master\telegram-twitter-forwarder-bot-master>main.py
Traceback (most recent call last):
File "C:\Users\user\Downloads\telegram-twitter-forwarder-bot-master\telegram-twitter-forwarder-bot-master\main.py", line 32, in
auth = tweepy.OAuthHandler(env('TWITTER_CONSUMER_KEY'), env('TWITTER_CONSUMER_SECRET'))
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\envparse.py", line 107, in call
return env(var, cast=cast, default=default)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\envparse.py", line 39, in env
value = os.environ[var]
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\os.py", line 681, in getitem
raise KeyError(key) from None
KeyError: 'TWITTER_CONSUMER_KEY'

thank you

Upload to server

I want to run the bot in server so that i can use the bot without using my computer. But i find some problem that when bot is uploaded to heroku.com. It will send all the tweet start from the day that i upload the bot. i guess the problem is from the database setting about the time? Is there any method to fix it?

Posting in channel

I have just set up the bot and it posts tweets in a group and to me in chat but I cannot seem to add it to a channel.

Is this supported? If so, how?

Bot failed to send chat

From log TwitterForwarderBot - INFO - Couldn't send tweet 767299741981954050 to chat 130145717: 'Bad Request: Url host is empty'

Any idea why this is happening? Used to work fine :/

Problem with videos and links

Problem with videos and links

Most of the videos can not be played only appears an image and some links are not previewed

Subscription being removed

While the account is active, not protected, and public, the following error occur:
Your subscription to @xxxxxx was removed because that profile is protected and can't be fetched.

[Proposal] Add #hashtags in sub command

What about adding hashtags in the sub command, so people can subscribe for updates coming from any author on a specific topic?
Command would change in Use /sub @username1 @username2 #hashtag1 #hashtag2...
Based on the first character the command will create two distinct lists containing usernames and hashtags to follow.

Migrate to PTB 20.0

I have been trying to migrate the bot to Python Telegram Bot v20.0... but I have been having problems with not being able to pass the classes correctly... I would appreciate some help...

One of the problems is that in the functional version here uses PTB v5.0... the bot is initialized with

updater = Updater(bot=TwitterForwarderBot(token, twapi))
dispatcher = updater.dispatcher
# set commands
dispatcher.add_handler(CommandHandler('start', cmd_start))

and now (v20) the ApplicationBuilder() is used, and I don't know how to start the class that forwards with the new bot instance form

application = ApplicationBuilder().token(token).build()
application.add_handler(CommandHandler("start", start))

Awesome logo

Hey there,

just wanted to mention that i really like how the logo resembles a horny bird that is about to fuck a flashlight.

Congrats on this epic logo

How to add the bot to a telegram channel

I successfully added the bot to a group because there was an option for it.
But I don't see any option for a channel?
How can I add the bot to a channel?

  • The inline mode simply doesn't work, it will get stuck in loading when you mention the bot username in the input field

Bot stopped working

Hi, I have been using this bot for awhile and works perfectly, but suddenly today the bot refused to work, it is still able to fetch new tweets but it wont keep running, it just stopped after sent tweets to me.

Traceback (most recent call last):
  File "main.py", line 38, in <module>
    bot.kb_interruptable_loop()
  File "/home/yoga/opt/python/kenaparusak/basebot.py", line 161, in kb_interruptable_loop
    self.loop()
  File "/home/yoga/opt/python/kenaparusak/basebot.py", line 151, in loop
    self.poll()
  File "/home/yoga/opt/python/kenaparusak/basebot.py", line 74, in poll
    upds = self.tg.getUpdates(offset=self.update_offset, timeout=self.POLL_TIMEOUT)
  File "/home/yoga/opt/python/venv/lib/python3.4/site-packages/telegram/bot.py", line 126, in decorator
    result = func(self, *args, **kwargs)
  File "/home/yoga/opt/python/venv/lib/python3.4/site-packages/telegram/bot.py", line 697, in getUpdates
    return [Update.de_json(x) for x in result]
  File "/home/yoga/opt/python/venv/lib/python3.4/site-packages/telegram/bot.py", line 697, in <listcomp>
    return [Update.de_json(x) for x in result]
  File "/home/yoga/opt/python/venv/lib/python3.4/site-packages/telegram/update.py", line 58, in de_json
    data['message'] = Message.de_json(data['message'])
KeyError: 'message'

Bot not read messages in channel

Hello

I've worked with the bot and worked like a charm on groups, but i can't make work on my public channel.

I've added my telegram bot to the target channel (as admin), but at the time to send my command, the bot did't reply and the action doesn't show on the terminal ( as "Getting updates")

There is any step that i've have ommited?

Thanks in advance

error when running main.py

hi, i get this error when i try to run the main.py
Traceback (most recent call last):
File "main.py", line 3, in
import tweepy
File "/home/ubuntu/Desktop/telegram-twitter-forwarder-bot-master/venv/lib/python3.8/site-packages/tweepy/init.py", line 17, in
from tweepy.streaming import Stream, StreamListener
File "/home/ubuntu/Desktop/telegram-twitter-forwarder-bot-master/venv/lib/python3.8/site-packages/tweepy/streaming.py", line 340
def _start(self, async):
^
SyntaxError: invalid syntax
any suggestion on how to fix it?

Script keeps crashing

Either TWITTER_ACCESS_TOKEN or TWITTER_ACCESS_TOKEN_SECRET environment variables are missing. Tweepy will be initialized in 'app-only' mode
2016-08-16 15:02:22,680 - TwitterForwarderBot - INFO - Initializing
2016-08-16 15:02:22,680 - JobQueue - DEBUG - Putting a FetchAndSendTweetsJob with t=0
2016-08-16 15:02:22,681 - JobQueue - DEBUG - Ticking jobs with t=1471377742.6814742
2016-08-16 15:02:22,681 - JobQueue - DEBUG - Peeked a FetchAndSendTweetsJob with t=0
2016-08-16 15:02:22,681 - JobQueue - DEBUG - About time! running
2016-08-16 15:02:22,681 - FetchAndSendTweetsJob - DEBUG - Fetching tweets...
2016-08-16 15:02:22,682 - JobQueue - DEBUG - Putting a FetchAndSendTweetsJob with t=1471377862.6814742
2016-08-16 15:02:22,682 - JobQueue - DEBUG - Peeked a FetchAndSendTweetsJob with t=1471377862.6814742
2016-08-16 15:02:22,682 - JobQueue - DEBUG - Next task isn't due yet. Finished!
Traceback (most recent call last):
File "main.py", line 38, in
bot.kb_interruptable_loop()
File "/home/leonfox/Telegram-Twitter/telegram-twitter-forwarder-bot/basebot.py", line 161, in kb_interruptable_loop
self.loop()
File "/home/leonfox/Telegram-Twitter/telegram-twitter-forwarder-bot/basebot.py", line 151, in loop
self.poll()
File "/home/leonfox/Telegram-Twitter/telegram-twitter-forwarder-bot/basebot.py", line 74, in poll
upds = self.tg.getUpdates(offset=self.update_offset, timeout=self.POLL_TIMEOUT)
File "/home/leonfox/Telegram-Twitter/telegram-twitter-forwarder-bot/venv/lib/python3.4/site-packages/telegram/bot.py", line 126, in decorator
result = func(self, _args, *_kwargs)
File "/home/leonfox/Telegram-Twitter/telegram-twitter-forwarder-bot/venv/lib/python3.4/site-packages/telegram/bot.py", line 697, in getUpdates
return [Update.de_json(x) for x in result]
File "/home/leonfox/Telegram-Twitter/telegram-twitter-forwarder-bot/venv/lib/python3.4/site-packages/telegram/bot.py", line 697, in
return [Update.de_json(x) for x in result]
File "/home/leonfox/Telegram-Twitter/telegram-twitter-forwarder-bot/venv/lib/python3.4/site-packages/telegram/update.py", line 58, in de_json
data['message'] = Message.de_json(data['message'])
KeyError: 'message'

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.