telegram

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

xk6-telegram

Build xk6 telegram

This is a k6 extension using the xk6 system.

❗ This is a proof of concept, isn't supported by the k6 team, and may break in the future. USE AT YOUR OWN RISK!

Contents

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Install xk6:
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
CGO_ENABLED=1
xk6 build --with github.com/maksimall89/xk6-telegram@latest

If you use Windows:

set CGO_ENABLED=1
xk6 build master --with github.com/maksimall89/xk6-telegram@latest

Usage

import http from "k6/http";
import telegram from "k6/x/telegram";

const conn = telegram.connect(`${__ENV.TOKEN}`, false);
const chatID = 123456789;

export function setup() {
    telegram.send(conn, chatID, "Starting test");
    telegram.sendReplay(conn, chatID, 1, "Replay 1 message from the chat");
}

export default function () {
    http.get('http://test.k6.io');
}

export function teardown() {
    telegram.send(conn, chatID, "Result <b>test</b> with HTML tag");
    telegram.shareImage(conn, chatID, "http://k6.io/logo.png");
    telegram.uploadImagePath(conn, chatID, "/home/k6/logo.png");
    telegram.getUpdate(conn, chatID);
}

Result output:

$ ./k6 run example.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: example.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)


running (00m00.8s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.7s/10m0s  1/1 iters, 1 per VU

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=683.33ms min=683.33ms med=683.33ms max=683.33ms p(90)=683.33ms p(95)=683.33ms
     iterations...........: 1   1.217797/s
     

Configure

Debug mode

if you need, you can debug mode on:

import telegram from "k6/x/telegram";

const conn = telegram.connect(`${__ENV.TOKEN}`, true);
Create telegram bot

Before using this extension, you need to create a bot in telegram use @BotFather after you need set environment variable TOKEN.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Telegram

type Telegram struct{}

func (*Telegram) Connect

func (t *Telegram) Connect(token string, isDebug bool) (*tgbotapi.BotAPI, error)

Connect to telegram bot API

func (*Telegram) GetUpdate

func (t *Telegram) GetUpdate(client *tgbotapi.BotAPI) tgbotapi.Update

GetUpdate last message from chat

func (*Telegram) Send

func (t *Telegram) Send(client *tgbotapi.BotAPI, chatID int64, text string) error

Send a text message to chat

func (*Telegram) SendReplay

func (t *Telegram) SendReplay(client *tgbotapi.BotAPI, chatID int64, replayID int, text string) error

SendReplay message to chat

func (*Telegram) ShareImage

func (t *Telegram) ShareImage(client *tgbotapi.BotAPI, chatID int64, fileID string) error

ShareImage exist a photo like http://myphoto.com/photo.png

func (*Telegram) UploadImageByte

func (t *Telegram) UploadImageByte(client *tgbotapi.BotAPI, chatID int64, photoBytes []byte) error

UploadImageByte a photo like bytes array

func (*Telegram) UploadImagePath

func (t *Telegram) UploadImagePath(client *tgbotapi.BotAPI, chatID int64, photoPath string) error

UploadImagePath a photo use local path to photo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL