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

wa-chat-server-telegram

v0.3.8

Published

wa-chat-server adapter for Telegram

Downloads

22

Readme

wa-chat-server-telegram

wa-chat-server-telegram is a wa-chat-server adapter for the Telegram messenger.

Create a Telegram Bot

  1. Contact BotFather from your Telegram messenger.
  2. Type /newbot and answer the questions.
  3. Save the token for further use.

Adapter Usage

Register The Adapter

An initialization of the wa-chat-server (in a chat application using wa-chat-server to communicate with Watson Assistant) with a wa-chat-server-telegram adapter looks like this:

require('dotenv').config();
import { WAChatServer, Types } from 'wa-chat-server';
import { WAChatServerTelegramAdapter } from 'wa-chat-server-telegram';
const server: WAChatServer = new WAChatServer((process.env as any) as Types.IWAChatServerConfig);
server.addAdapter('telegram', WAChatServerTelegramAdapter);
server.serve();

Configure The Adapter

We must set the following environment variables (e. g. in .env):

Variable | Obligatory | Meaning -------- | ---------- | ------- adapter__telegram__token | Y | The Bot token generated by the BotFather | adapter__telegram__apiUrl | Y | The Telegram endpoint, typically https://api.telegram.org) | adapter__telegram__callbackUrl | Y | The endpoint to be called by Telegram (without the path adapters/telegram | adapter__telegram__webhookLifetimeS | N | The Telegram webhook lifetime in seconds. Whenever the lifetime is reached a new webhook URL (containing a random token) is generated. 0 by default which means "generate URL only once at application startup" |

Local Development

HTTP Tunnel Setup

For local development we need to set up a secure tunnel localhost and Telegram. We can use ngrok for this purpose:

ngrok http 3023

opens a tunel and gives us a public HTTPS URL to be used by Telegram (without an ngrook account the lifetime of the tunnel will be 2 hours). We must then use the Telegram API to configure this URL in Telegram:

export ENDPOINT="[NGROK_URL]"; export TOKEN=[BOT_TOKEN]; curl -X POST -H "Content-Type:application/json" -d "{\"url\":\"$ENDPOINT/adapters/telegram\"}" "https://api.telegram.org/bot$TOKEN/setwebhook"

We may inspect the communication tunneled by ngrok to localhost on http://localhost:4040.

IMPORTANT: Don't do it for a Telegram bot that is already attached to some server installation. Create your own Telegram bot instead.

Transpilation

Run

npm run dev

Linking The Library to The Chat Project

Run

npm link

from the wa-chat-server-telegram root folder.

and then

npm link wa-chat-server-telegram

from the root of your chat application.