Skip to content

Commit

Permalink
Added sendVenue method
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Mar 7, 2022
1 parent 57a4f4b commit 9b6948a
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 7 deletions.
65 changes: 58 additions & 7 deletions src/structure/TelegramAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import EventEmitter from "eventemitter3";
import FormData from "form-data";
import { ReadStream } from "node:fs";
import fetch, { RequestInit } from "node-fetch";
import { URLSearchParams } from "node:url";
import { IMessage } from "../types/IMessage";
Expand All @@ -9,6 +11,7 @@ import {
editMessageLiveLocationOptions,
sendLocationOptions,
sendMediaGroupOptions,
sendVenueOptions,
sendVoiceOptions,
stopMessageLiveLocationOptions,
} from "./methodsOptions";
Expand Down Expand Up @@ -43,9 +46,6 @@ import {
IInputMediaVideo,
} from "../types";

import FormData from "form-data";
import { ReadStream } from "node:fs";

export class TelegramAPI {
/**
* Telegram API token
Expand Down Expand Up @@ -763,13 +763,13 @@ export class TelegramAPI {
* @param chat_id Unique identifier for the target chat or username of the target channel.
* @param voice Audio file to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
* @param options
* @returns
* @returns IMessage
*/
async sendVoice(
chat_id: string | number,
voice: ReadStream | string,
options?: sendVoiceOptions
) {
): Promise<IMessage> {
let params = {};
let postOptions = {};
const form = new FormData();
Expand Down Expand Up @@ -872,9 +872,10 @@ export class TelegramAPI {
* Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Messages that were sent is returned.
* @param chat_id Unique identifier for the target chat or username of the target channel.
* @param media A JSON-serialized array describing messages to be sent, must include 2-10 items
* @param options
* @returns
* @param options sendMediaGroupOptions
* @returns IMessage
*/

async sendMediaGroup(
chat_id: number | string,
media:
Expand Down Expand Up @@ -925,6 +926,7 @@ export class TelegramAPI {
* @param options sendLocationOptions
* @returns IMessage[]
*/

async sendLocation(
chat_id: string | number,
latitude: number,
Expand Down Expand Up @@ -1030,6 +1032,55 @@ export class TelegramAPI {
return send;
}

/**
* Use this method to send information about a venue. On success, the sent Message is returned.
* @param chat_id Unique identifier for the target chat or username of the target channel
* @param latitude Latitude of the venue
* @param longitude Longitude of the venue
* @param title Name of the venue
* @param address Address of the venue
* @param options sendVenueOptions
* @returns IMessage
*/

async sendVenue(
chat_id: string | number,
latitude: number,
longitude: number,
title: string,
address: string,
options?: sendVenueOptions
): Promise<IMessage> {
let params = {};

if (options) {
params = {
chat_id: chat_id,
latitude: latitude,
longitude: longitude,
title: title,
address: address,
...options,
};
} else {
params = {
chat_id: chat_id,
latitude: latitude,
longitude: longitude,
title: title,
address: address,
};
}

const qs = this.qs(params);
const send: IMessage = await this.sendRequest(this.endpoint + "sendVenue", {
body: qs,
method: "POST",
});

return send;
}

private isReadableStream = (val: any) =>
val !== null &&
typeof val === "object" &&
Expand Down
44 changes: 44 additions & 0 deletions src/structure/methodsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,47 @@ export interface stopMessageLiveLocationOptions {
*/
reply_markup?: IInlineKeyboardMarkup;
}

export interface sendVenueOptions {
/**
* Foursquare identifier of the venue.
*/
foursquare_id?: string;
/**
* Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
*/
foursquare_type?: string;
/**
* Google Places identifier of the venue
*/
google_place_id?: string;
/**
* Google Places type of the venue.
* @see Supported Types https://developers.google.com/maps/documentation/places/web-service/supported_types
*/
google_place_type?: string;
/**
* Sends the message silently. Users will receive a notification with no sound.
*/
disable_notification?: boolean;
/**
* Protects the contents of the sent message from forwarding and saving
*/
protect_content?: boolean;
/**
* If the message is a reply, ID of the original message
*/
reply_to_message_id?: number;
/**
* Pass True, if the message should be sent even if the specified replied-to message is not found
*/
allow_sending_without_reply?: boolean;
/**
* Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
*/
reply_markup?:
| IInlineKeyboardMarkup
| IReplyKeyboardMarkup
| IReplayKeyboardRemove
| IForceReply;
}

0 comments on commit 9b6948a

Please sign in to comment.