Skip to content

Commit

Permalink
Added sendLocation, editMessageLiveLocation and `stopMessageLiveL…
Browse files Browse the repository at this point in the history
…ocation` methods
  • Loading branch information
naseif committed Mar 5, 2022
1 parent 83c9812 commit 5184d4f
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 1 deletion.
121 changes: 120 additions & 1 deletion src/structure/TelegramAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { IMessage } from "../types/IMessage";
import { IUpdate } from "../types/IUpdate";
import { IUpdateOptions } from "../types/IUpdateOptions";
import { IUser } from "../types/IUser";
import { sendMediaGroupOptions, sendVoiceOptions } from "./methodsOptions";
import {
editMessageLiveLocationOptions,
sendLocationOptions,
sendMediaGroupOptions,
sendVoiceOptions,
stopMessageLiveLocationOptions,
} from "./methodsOptions";
import {
sendMessageOptions,
sendPollOptions,
Expand Down Expand Up @@ -911,6 +917,119 @@ export class TelegramAPI {
return send;
}

/**
* Use this method to send point on the map. 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 location
* @param longitude Longitude of the location
* @param options sendLocationOptions
* @returns IMessage[]
*/
async sendLocation(
chat_id: string | number,
latitude: number,
longitude: number,
options?: sendLocationOptions
): Promise<IMessage> {
let params = {};

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

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

return send;
}

/**
* Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
* @param latitude Latitude of new location
* @param longitude Longitude of new location
* @param options editMessageLiveLocationOptions
* @returns IMessage | boolean
*/

async editMessageLiveLocation(
latitude: number,
longitude: number,
options?: editMessageLiveLocationOptions
): Promise<boolean | IMessage> {
let params = {};

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

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

return send;
}

/**
* Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
* @param options stopMessageLiveLocationOptions
* @returns IMessage | boolean
*/

async stopMessageLiveLocation(
options?: stopMessageLiveLocationOptions
): Promise<boolean | IMessage> {
let params = {};

if (options) {
params = {
...options,
};
}

let qs = this.qs(params);

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

return send;
}

private isReadableStream = (val: any) =>
val !== null &&
typeof val === "object" &&
Expand Down
3 changes: 3 additions & 0 deletions src/structure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ export {
sendVoiceOptions,
sendVideoNoteOptions,
sendMediaGroupOptions,
sendLocationOptions,
editMessageLiveLocationOptions,
stopMessageLiveLocationOptions,
} from "./methodsOptions";
93 changes: 93 additions & 0 deletions src/structure/methodsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,96 @@ export interface sendMediaGroupOptions {
*/
allow_sending_without_reply?: boolean;
}

export interface sendLocationOptions {
/**
* The radius of uncertainty for the location, measured in meters; 0-1500
*/
horizontal_accuracy?: number;
/**
* Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.
*/
live_period?: number;
/**
* For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
*/
heading?: number;
/**
* For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
*/
proximity_alert_radius?: number;
/**
* 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;
}

export interface editMessageLiveLocationOptions {
/**
* Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format
*/
chat_id?: number | string;
/**
* Required if inline_message_id is not specified. Identifier of the message to edit
*/
message_id?: number;
/**
* Required if chat_id and message_id are not specified. Identifier of the inline message
*/
inline_message_id?: string;
/**
* The radius of uncertainty for the location, measured in meters; 0-1500
*/
horizontal_accuracy?: number;
/**
* Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
*/
heading?: number;
/**
* Maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
*/
proximity_alert_radius?: number;
/**
* A JSON-serialized object for a new inline keyboard.
*/
reply_markup?: IInlineKeyboardMarkup;
}

export interface stopMessageLiveLocationOptions {
/**
* Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel
*/
chat_id?: number | string;
/**
* Required if inline_message_id is not specified. Identifier of the message with live location to stop
*/
message_id?: number;
/**
* Required if chat_id and message_id are not specified. Identifier of the inline message
*/
inline_message_id?: string;
/**
* A JSON-serialized object for a new inline keyboard.
*/
reply_markup?: IInlineKeyboardMarkup;
}

0 comments on commit 5184d4f

Please sign in to comment.