Giter Site home page Giter Site logo

gotham13 / fb-to-tg-group-connect Goto Github PK

View Code? Open in Web Editor NEW
8.0 0.0 2.0 384 KB

PUBLISHES POSTS SENT ON FACEBOOK GROUP TO TELEGRAM GROUP

License: MIT License

Python 100.00%
telegram-bot-api python-telegram-bot facebook-sdk facebook-graph-api bridge

fb-to-tg-group-connect's Introduction

FB-TO-TG-GROUP-CONNECT

PUBLISHES POSTS SENT ON FACEBOOK GROUP TO TELEGRAM GROUP

LIBRARIES USED

  • PYTHON-TELEGRAM-BOT
  • APSCHEDULER
  • FACEBOOK-SDK

USAGE

PREREQUISITES

  • python 3 or above

CONFIGURATION

  • Create your bot and Get your telegram bot token from BotFather
  • Get your facebook user access token by creating an app on facebook Facebook developers
  • If the group is a closed group you will require to have the user access token of an admin and user-managed-group permission for your app
  • get your facebook group id
  • you can get your facebook group id by first finding your user id by using /me/id endpoint of facebook graph api in Graph api explorer then
    running /{user-id}/groups
  • Get your telegram chat id
    • You can get your chat id by first messaging to the bot and then checking the url https://api.telegram.org/botYourBOTToken/getUpdates
      It will look somewhat like this
      {"update_id":8393,"message":{"message_id":3,"from":{"id":7474,"first_name":"AAA"},"chat":{"id":,"title":""},"date":25497,"new_chat_participant":{"id":71,"first_name":"NAME","username":"YOUR_BOT_NAME"}}}
      the id of the chat object is your chat id
  • Get your telegram group id by adding bot to the group and using the same method as above
  • Edit the config.ini file with your credentials. You can also put your persistent storage point if you will be using OPENSHIFT ONLINE to host the bot (If name of your volume is df then put /df/ in the field) otherwise just leave the field blank

RUNNING ON LOCAL PC

  • pip install requirements.txt in console
  • run app.py script
  • enjoy

HOSTING ON OPENSHIFT ONLINE

  • edit the config.ini file
  • save all the files in a repository on github
  • create an account on REDHAT OPENSHIFT ONLINE
  • select the location of your server
  • wait for a few days till you recieve confirmation
  • after recieving confirmation, login and create new application
  • select python 3.4 or above
  • select name and everything
  • enter the url of the github repository
  • wait for application to start
  • enjoy

REBUILDING PROJECT ON OPENSHIFT ONLINE

when you want to rebuild your project

  • first of all go to deployments and select the latest deployment

  • downscale the no of pods to 0 and wait for it to happen

  • IMPORTANT go to deployment configuration and detach the storage. A deployment will start, let it finish

  • Go to builds, select name and click on start build

  • After finishing build a deployment will start, let it finish

  • Go back to deployment configuration and add storage with same mount point as previous and wait for a new deployment

  • After deployment finishes, go to deployments. Select latest and scale the pod to 1.

  • YOU CAN REMOVE YOUR GITHUB REPOSITORY BUT MAKE SURE TO RECREATE IT WHEN REBUILDING YOUR PROJECT

EXAMPLE

alt text
alt text

fb-to-tg-group-connect's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fb-to-tg-group-connect's Issues

Error by running app.py

I'm getting the following message by running app.py

Traceback (most recent call last):
File "/usr/lib/python3.7/configparser.py", line 788, in get
value = d[option]
File "/usr/lib/python3.7/collections/init.py", line 914, in getitem
return self.missing(key) # support subclasses that define missing
File "/usr/lib/python3.7/collections/init.py", line 906, in missing
raise KeyError(key)
KeyError: 'admin_chat_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "app.py", line 46, in
adminlist=str(config.get('telegram','admin_chat_id')).split(',')
File "/usr/lib/python3.7/configparser.py", line 791, in get
raise NoOptionError(option, section)
configparser.NoOptionError: No option 'admin_chat_id' in section: 'telegram'

Would be very happy if somebody can help me :)

Access Token Limit reached

Hey! First of all: Thank you for yout great app. I'm using it a lot, made some changes and normally it works very good. But there is one problem from time to time, that the API Call limit is reached and I don't know why. In the log there are some error codes, I don't understand. First, here is the code out of my syslog. I also changed some code in the app.py like the facebook sdk version (I use 3.1) and some linking things, but I don't think they interference with the APP Call limit (I also changed it to 3:50 from 3:40):

Dec 3 10:39:20 74213 app.py[4659]: 2018-12-03 10:39:20,457 - apscheduler.executors.default - INFO - Job "fetch (trigger: interval[0:03:50], next run at: 2018-12-03 11:43:07 EET)" executed successfully Dec 3 10:43:07 74213 app.py[4659]: 2018-12-03 10:43:07,910 - apscheduler.executors.default - INFO - Running job "fetch (trigger: interval[0:03:50], next run at: 2018-12-03 11:46:57 EET)" (scheduled at 2018-12-03 11:43:07.909630+02:00) Dec 3 10:43:15 74213 app.py[4659]: 2018-12-03 10:43:15,805 - apscheduler.executors.default - ERROR - Job "fetch (trigger: interval[0:03:50], next run at: 2018-12-03 11:46:57 EET)" raised an exception Dec 3 10:43:15 74213 app.py[4659]: Traceback (most recent call last): Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 402, in _make_request Dec 3 10:43:15 74213 app.py[4659]: six.raise_from(e, None) Dec 3 10:43:15 74213 app.py[4659]: File "<string>", line 2, in raise_from Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 398, in _make_request Dec 3 10:43:15 74213 app.py[4659]: httplib_response = conn.getresponse() Dec 3 10:43:15 74213 app.py[4659]: File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse Dec 3 10:43:15 74213 app.py[4659]: response.begin() Dec 3 10:43:15 74213 app.py[4659]: File "/usr/lib/python3.5/http/client.py", line 297, in begin Dec 3 10:43:15 74213 app.py[4659]: version, status, reason = self._read_status() Dec 3 10:43:15 74213 app.py[4659]: File "/usr/lib/python3.5/http/client.py", line 258, in _read_status Dec 3 10:43:15 74213 app.py[4659]: line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") Dec 3 10:43:15 74213 app.py[4659]: File "/usr/lib/python3.5/socket.py", line 576, in readinto Dec 3 10:43:15 74213 app.py[4659]: return self._sock.recv_into(b) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/lib/python3.5/ssl.py", line 937, in recv_into Dec 3 10:43:15 74213 app.py[4659]: return self.read(nbytes, buffer) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/lib/python3.5/ssl.py", line 799, in read Dec 3 10:43:15 74213 app.py[4659]: return self._sslobj.read(len, buffer) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/lib/python3.5/ssl.py", line 583, in read Dec 3 10:43:15 74213 app.py[4659]: v = self._sslobj.read(len, buffer) Dec 3 10:43:15 74213 app.py[4659]: socket.timeout: The read operation timed out Dec 3 10:43:15 74213 app.py[4659]: During handling of the above exception, another exception occurred: Dec 3 10:43:15 74213 app.py[4659]: Traceback (most recent call last): Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/utils/request.py", line 203, in _request_wrapper Dec 3 10:43:15 74213 app.py[4659]: resp = self._con_pool.request(*args, **kwargs) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/request.py", line 70, in request Dec 3 10:43:15 74213 app.py[4659]: **urlopen_kw) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/request.py", line 148, in request_encode_body Dec 3 10:43:15 74213 app.py[4659]: return self.urlopen(method, url, **extra_kw) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/poolmanager.py", line 244, in urlopen Dec 3 10:43:15 74213 app.py[4659]: response = conn.urlopen(method, u.request_uri, **kw) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 666, in urlopen Dec 3 10:43:15 74213 app.py[4659]: _stacktrace=sys.exc_info()[2]) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/util/retry.py", line 347, in increment Dec 3 10:43:15 74213 app.py[4659]: raise six.reraise(type(error), error, _stacktrace) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/packages/six.py", line 686, in reraise Dec 3 10:43:15 74213 app.py[4659]: raise value Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 617, in urlopen Dec 3 10:43:15 74213 app.py[4659]: chunked=chunked) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 405, in _make_request Dec 3 10:43:15 74213 app.py[4659]: exc_cls=ReadTimeoutError) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 321, in _raise_timeout Dec 3 10:43:15 74213 app.py[4659]: raise exc_cls(*args) Dec 3 10:43:15 74213 app.py[4659]: telegram.vendor.ptb_urllib3.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=5.0) Dec 3 10:43:15 74213 app.py[4659]: During handling of the above exception, another exception occurred: Dec 3 10:43:15 74213 app.py[4659]: Traceback (most recent call last): Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/apscheduler/executors/base.py", line 125, in run_job Dec 3 10:43:15 74213 app.py[4659]: retval = job.func(*job.args, **job.kwargs) Dec 3 10:43:15 74213 app.py[4659]: File "/root/telegrambot/app.py", line 142, in fetch Dec 3 10:43:15 74213 app.py[4659]: bot.send_message(chat_id=chatids, text="Your facebook user access token might have expired") Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/bot.py", line 65, in decorator Dec 3 10:43:15 74213 app.py[4659]: result = func(self, *args, **kwargs) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/bot.py", line 90, in decorator Dec 3 10:43:15 74213 app.py[4659]: result = self._request.post(url, data, timeout=kwargs.get('timeout')) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/utils/request.py", line 309, in post Dec 3 10:43:15 74213 app.py[4659]: headers={'Content-Type': 'application/json'}) Dec 3 10:43:15 74213 app.py[4659]: File "/usr/local/lib/python3.5/dist-packages/telegram/utils/request.py", line 205, in _request_wrapper Dec 3 10:43:15 74213 app.py[4659]: raise TimedOut() Dec 3 10:43:15 74213 app.py[4659]: telegram.error.TimedOut: Timed out Dec 3 10:46:57 74213 app.py[4659]: 2018-12-03 10:46:57,910 - apscheduler.executors.default - INFO - Running job "fetch (trigger: interval[0:03:50], next run at: 2018-12-03 11:50:47 EET)" (scheduled at 2018-12-03 11:46:57.909630+02:00)
Perhaps you understand the errors out of the syslog. When I go to facebook it also shows me that the call count is about 101% at the moment - so it blocks every new call (and also the bot is sending me "Your facebook token might have expired" every call/3:50minute. The token is a never expiring token.

Thank you!
David

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.