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

telegram-bot-now

v1.15.4

Published

A NodeJs-based Telegram bot for the Now serverless platform

Downloads

54

Readme

npm version

Telegram Bot Now

This project offers a skeleton for easily creating Telegram bots using the Now serverless platform. For more information on Now, see:

https://zeit.co/now

Install

The project is available from NPM and can be installed in the usual way:

$ npm install --save telegram-bot-now

But to deploy your bot you'll also need the Now client. Install it like this:

$ npm install -g now

Scaffolding

When the package is installed, it creates a symlink to our maker utility in your project's root directory. You can thus grab our skeleton code like this:

$ ./mk scaffold

The main entry point for your server is named server.js so if your current package.json is using index.js you may want to change the line below (or rename the file, but if you do that don't forget to also change the now.json):

  "main": "server.js",

Additionally, you may want to have the following as well:

"scripts": {
    "start": "micro",
    "dev": "micro-dev",
    "debug": "node --inspect node_modules/.bin/micro-dev"
},

which will allow you to start your server locally (use npm run dev in development so use the micro-dev engine), and if you use Microsoft VS Code, you can create a debug configuration (in your .vscode/launch.json) like this, to allow debugging:

{
    "type": "node",
    "request": "launch",
    "name": "Launch via NPM",
    "runtimeExecutable": "npm",
    "runtimeArgs": [
        "run-script",
        "debug"
    ],
    "port": 9229,
    "envFile": "${workspaceFolder}/.env"
}

Finally, if for whatever reason the symlink to mk was not properly created, you can create it by hand like this:

ln -s node_modules/telegram-bot-now/mk

Please note: the make utility will not work on Windows. Users of that operating system are encouraged to install Cygwin or another bash shell available

Deploy

Before you can deploy your project you'll need an account on the Now network -- see the link on the preface to this document for creating one

To bind your project implementation to the bot you created, you'll need to supply the bot key that BotFather generated. Running the command below will prompt you to verify the Now account you created and will also ask for the bot key:

$ ./mk secrets

The above will store your bot key in your environment file (.env), which is located on your project root. Any sensitive information your project needs to store, such as keys or credentials to external systems, should be managed as Now secrets and can be placed in the environment file. Just remember that if you change the contents of this file you'll need to run the above command again

Now, to deploy your project is super easy. Run:

$ ./mk

...which will synchronise the local files in your project with the Now servers and automatically bind the deployment to your Telegram bot's webhook

To see logs on your deployment:

$ ./mk logs

To see other commands supported by the make utility:

$ ./mk --help

Test

You should now be able to go to Telegram, find the bot and start chatting! If you used our scaffolding you can greet the bot:

/hello

and it should greet you back

Debug

If you need to run your bot locally (for debugging), edit the package.json, adding a new script:

    "dev": "micro-dev",

and then:

$ npm install --save-dev micro-dev # in case you don't have it installed
$ npm run dev

Your environment file is also compatible with the Microsoft VS Code debugger. Just make sure your .vscode/launch.json file contains the following line (as previously shown):

    "envFile": "${workspaceFolder}/.env"

Additional Reading

For a complete description of how to set up routes, create dialogues, the various utilities provided in the module, and troubleshooting guidance, please read the Medium article:

A Telegram bot in the serverless Now

Contribute

If there's some enhancement you'd like to contribute, please clone the project, modify it and submit a pull request:

$ git clone https://github.com/ekkis/telegram-bot-now.git

Support

Create a ticket on Github. Reach out to me on Telegram. You'll find me as @ekkis