npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@levellr/crossgram

v0.2.0

Published

Repost Tweets to Telegram automatically

Downloads

23

Readme

Crossgram

Repost Tweets to Telegram automatically. Built by Levellr.

Crossgram is a TypeScript library and web service you can use to automatically repost Tweets to Telegram chats, groups, supergroups or channels using a Telegram Bot.

You can:

  • Follow one Twitter account or many
  • Reposts tweets into one Telegram chat or many
  • Use a single Telegram bot, or use a different bot for each chat

A single Crossgram instance even can be used to stream Tweets from multiple accounts to multiple Telegram chats using multiple Telegram bots. For example, one Crossgram instance can repost:

Twitter shortlinks are automatically expanded — no more mysterious 't.co' links in your chat!


Need a no-code solution? 👷

If you don't code and you just want a bot to automatically repost Tweets from Twitter to Telegram for you, we're running a closed beta that can help you out.

Drop us a line and tell us about your Telegram community to find out if you're eligible to join.


Getting started

To get started, you'll need:

Remember to add the bot to the channel, group or supergroup with permission to post content.

Running Crossgram

Clone the project:

  git clone https://github.com/levellr/crossgram.git

Go to the project directory:

  cd crossgram

Install dependencies:

  npm install

Start the script:

  npm run start

Deploying Crossgram

Use a platform of your choice, or deploy in one click:

Deploy to Render

Configuration

The web service (via npm run start or bin/stream.ts) is configured using environment variables.

The following environment variables are required, and the script will not start without them:

| Environment variable | Description | | ------------------------- | ------------------------------------------------------------------------------------------------------- | | TELEGRAM_BOT_TOKENS | A comma-separated list of bot tokens for Telegram bots created via @BotFather | | TELEGRAM_CHAT_IDS | A comma-separated list of Telegram chat IDs to which the Tweets should be posted | | TWITTER_USERNAMES | A comma-separated list of Twitter usernames to watch and repost to Telegram | | TWITTER_CONSUMER_KEY | The consumer key for a Twitter API client | | TWITTER_CONSUMER_SECRET | The consumer secret for a Twitter API client |

The environment variable TELEGRAM_CHAT_IDS must contain either exactly one value or exactly as many values as there are TWITTER_USERNAMES.

  • If there is one chat ID, all tweets from all usernames in TWITTER_USERNAMES will be streamed to the specified chat ID.
  • If there are multiple chat IDs, the script will iterate through TELEGRAM_CHAT_IDS AND TWITTER_USERNAMES in a pairwise fashion. It will stream tweets from the first username to the first chat ID, the second username to the second chat ID, etc.

The environment variable TELEGRAM_BOT_TOKENS must contain either exactly one value or exactly as many values as there are TELEGRAM_CHAT_IDS.

  • If there is one bot token, tweets destined for all chat IDs will be sent via the specified bot token.
  • If there are multiple chat IDs, the script will iterate through TELEGRAM_BOT_TOKENS AND TELEGRAM_CHAT_IDS in a pairwise fashion. It will send tweets to the first chat ID using the first bot token, to the second chat ID using the second bot token, etc.

Neither chat IDs or bot tokens have to be unique.

If specified in a .env file in the root of the project, environment variables will be automatically loaded at app start.

Using Crossgram as a library

Install Crossgram with npm:

  npm install @levellr/crossgram

Then use the library:

const { TwitterStreamer } = require('@levellr/crossgram');

async function main() {
  console.log('Starting Twitter API client');

  const streamer = await TwitterStreamer.create({
    twitterAppKey: 'TWITTER_CONSUMER_KEY',
    twitterAppSecret: 'TWITTER_CONSUMER_SECRET',
  });

  // Register a stream from Twitter to Telegram
  console.log(`Registering stream`);
  await streamer.registerStream({
    twitterUsername: 'TWITTER_USERNAME',
    telegramBotToken: 'TELEGRAM_BOT_TOKEN',
    telegramChatId: 'TELEGRAM_CHAT_ID',
  });
}

main();

You can also use module imports:

import { TwitterStreamer } from '@levellr/crossgram';

Testing

  npm run test

Code formatting and linting

# code linting with eslint
$ npm run lint

# formating with Prettier
$ npm run format

Contributing

Contributions welcome! Please start with an issue before making a pull request so we can make sure we're all on the same page.

Check out our contribution guidelines for this project for more information.

License

Crossgram is open-source under the GNU Affero General Public License Version 3 (AGPLv3).