api Telegram webhook : how can delete new_chat_participant message - telegram-bot

I created a bot via webhook method of api telegram and It's okay and working.
but I want know how can delete any new_chat_participant messages before sending message by members.
You know that telegram don't send request to your hook url until have not any message with members !!!!!!!
I need just message_id for example when a member add an another to supper group.

Set /setprivacy to disable in #BotFather to receive the whole actions and messages from your group. (In order to delete these messages, the bot must has access to messages in the group, needs to be administrator).
When new member has been added to group, you will receive a json in your webhook something like this:
{ update_id: 123123123,
message:
{ message_id: 2599, // Pay attention to this message id
from: {
...
},
chat: {
id: -987372183 // This is your group's id
...
},
date: 1582378239,
new_chat_participant: { // Field when new member is added to group
}
...
}
Now you need to send a post request to Telegram to delete this message (action). The request is:
request.post("https://api.telegram.org/botYOUR_BOT_TOKEN/deleteMessage?chat_id=GROUP_ID&message_id=MESSAGE_ID_RECEIVED", ... )
Hope this helps.

Related

From attribute inside node mailer message not working always keep sending mail through default account which is used for creating account

let message={
from:email,
to:emails,
text:'Please join the meeting',
subject:`You are Invited for ${meetingName}`,
html:mail
}
Above is my message object the from attribute is not working. I want to send email from logged in user to the user given by him , but node mailer uses the email (my email which is configured at auth) it must use email given in from tag.
const config={
service:'gmail',
auth: {
user:"xx#gmail.com",
pass: ""
},
port:465,
host:'smtp.gmail.com'
}
always uses xx#gmail.com instead of logged in user

bot.telegram.getChat does not return the message of a specific user

I am trying to setup my bot so that it will 'listen' to a specific user and print out any incoming message.
I have already setup a bot in telegram using BotFather. This is what I have so far
const { Telegraf } = require('telegraf')
const bot = new Telegraf('my_bot_token_here');
bot.telegram.getChat(Chat_Id).then(function(chat) {
console.log('chat info', chat);
});
The object does not contain the user message.
Any advice on this is appreciated.
Yes, absolutely. You need to check the 'from' field in the message before executing your logic.
Telegram API

React Native Expo Push notification for specific user

Expo allows you to send notification by device id which is ambiguous and not great for my use case, how can i send notification that only specific user will receive? for example can i pass user id or username besides device id?
this is the body request body:
{
to: pushToken, // user id or topic?
body: 'test notification',
data: { withSome: 'data' }
}
You have to create a db table where you'll record user_id / username & device_token in order to be able to send notification to a user by his user_id or username.

Watch for changes to calendar, when to make request

When watching for changes to a collection of events on a given calendar, how often do I need to make a watch request?
Where would I put my code to make a watch request? Does it only need to be done once?
My code below gets an access token and makes a post to create a watch channel, however I'm not sure where to host the code or how often I need to run it:
let { google } = require("googleapis");
let functions = require("firebase-functions");
let privatekey = require("./config.json");
let axios = require("axios");
let jwt = new google.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key,
["https://www.googleapis.com/auth/calendar"]
);
const token = await jwt.authorize();
let headers = {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json;charset=UTF-8",
Authorization: token.token_type + " " + token.access_token
};
let data = {
id: randomId,
type: "web_hook",
address: "https://rguc-calendars.firebaseapp.com/notifications",
params: {
ttl: 3600
}
};
axios
.post(
"https://www.googleapis.com/calendar/v3/calendars/thirdyear#rguc.co.uk/events/watch",
data,
{ headers }
)
.then(function(response) {
// success
})
.catch(function(error) {
// error
});
push notifications
The Google Calendar API provides push notifications that let you watch
for changes to resources. You can use this feature to improve the
performance of your application. It allows you to eliminate the extra
network and compute costs involved with polling resources to determine
if they have changed. Whenever a watched resource changes, the Google
Calendar API notifies your application.
Register the domain of your receiving URL.
For example, if you plan to use https://example.com/notifications as your receiving URL, you need to register https://example.com.
Set up your receiving URL, or "Webhook" callback receiver.
This is an HTTPS server that handles the API notification messages that are triggered when a resource changes.
Set up a notification channel for each resource endpoint you want to watch.
A channel specifies routing information for notification messages. As part of the channel setup, you identify the specific URL where you want to receive notifications. Whenever a channel's resource changes, the Google Calendar API sends a notification message as a POST request to that URL.
Once you have set up the watch google will notify you when ever there is a change you wont have to call it again.

Why Icinga2 telegram notification fails in specific services?

I have created custom telegram notification very similar to email notifications. The problem is that it works for hosts and most of the services but not for all of them.
I do not post the *.sh files in scripts folder as it works!
In constants.conf I have added the bot token:
const TelegramBotToken = "MyTelegramToken"
I wanted to manage telegram channels or chat ids in users file, so I have users/user-my-username.conf as below:
object User "my-username" {
import "generic-user"
display_name = "My Username"
groups = ["faxadmins"]
email = "my-username#domain.com"
vars.telegram_chat_id = "#my_channel"
}
In templates/templates.conf I have added the below code:
template Host "generic-host-domain" {
import "generic-host"
vars.notification.mail.groups = ["domainadmins"]
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
template Service "generic-service-fax" {
import "generic-service"
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
And in notifications I have:
template Notification "telegram-host-notification" {
command = "telegram-host-notification"
period = "24x7"
}
template Notification "telegram-service-notification" {
command = "telegram-service-notification"
period = "24x7"
}
apply Notification "telegram-notification" to Host {
import "telegram-host-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
apply Notification "telegram-notification" to Service {
import "telegram-service-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
This is all I have. As I have said before it works for some services and does not work for other services. I do not have any configuration in service or host files for telegram notification.
To test I use Icinga web2. Going to a specific service in a host and send custom notification. When I send a custom notification I check the log file to see if there is any error and it says completed:
[2017-01-01 11:48:38 +0000] information/Notification: Sending reminder 'Problem' notification 'host-***!serviceName!telegram-notification for user 'my-username'
[2017-01-01 11:48:38 +0000] information/Notification: Completed sending 'Problem' notification 'host-***!serviceName!telegram-notification' for checkable 'host-***!serviceName' and user 'my-username'.
I should note that email is sent as expected. There is just a problem in telegram notifications for 2 services out of 12.
Any idea what would be the culprit? What is the problem here? Does return of scripts (commands) affect this behaviour?
There is no Telegram config in any service whatsoever.
Some telegram commands may fail due to markdown parser.
I've encountered this problem:
If service name has one underscore ('_'), then parser will complain about not closed markdown tag and message will not be sent