Hi everyone,
How about running your API collections and getting an informative report directly to the Telegram? A cool combination of two great tools - Newman and Telegram Bot API will help you to do this.
-
Firstly, in order to receive notifications and reports in the Telegram, you need to create an API bot with the help of the @BotFather. This is very easy to do and there are a lot of instructions on the Internet how to do it. The main thing here is you need to get a unique authentication
token
of your bot to access the HTTP API. -
Select an existing or create new Telegram group (public or private) to receive notifications and reports there. All you need in this step is to get a
chat ID
of your group. This can be easily done using special bots inside Telegram, for example 'Get My ID' bot, just forward any message from your group to this bot. Then add your bot to the created group and give bot the admin permission to send messages to the group. You can also find all instructions on the Internet. -
Fork this repository, create new project in IDE on your computer using copied link of forked repository. Install the required node modules in the project. For this open a built-in terminal in your IDE and run the following command:
npm i
. Ok, now you set all required dependencies. -
In the root of the project, find a file named
.env.example
and rename it to.env
. Then open this file and replace the values of all environment variables there with your own values:
COLLECTION_PATH
is the path to a json-file on your computer containing a collection of your API requests.ENVIRONMENT_PATH
is the path to a json-file on your computer containing the environment variables. You can export them for example fromPostman
.TOKEN
is the token of your Telegram API Bot (see step #1).CHAT_ID
is the chat ID of your group (see step #2). Try not to make any mistakes here. No quotation marks or another extra characters - everything is exactly as in the contained example. Please note that the paths to the files contain the names of these files and end with.json
. Don't forget to save your changes (Crtl+S
).
Well, it's time to run your collection with Newman and get the html-report exactly to your Telegram group. For this use command: npm test
.
Immediately in the terminal you can see a special green bar that indicates the progress of running the collection. When the running is over a new directory report
will appear in the root of the project in which the report.html
file will be placed. It will be created as part of the Newman run. In a couple of seconds you will receive a notification and an html-report directly to your Telegram group. After sending the report, also you will see a message in the terminal that the report was successfully sent to Telegram.
It is important to note that you can receive such reports in absolutely any Telegram group to which you add your bot with administrator rights.
Here you can see examples of notifications and reports received in my group 'API alerts', as well as snippets of the html-report:
You can find a detailed description of this project in my article.
Here were used following dependencies:
More information about the Telegram Bot API you can find here.