Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove service message #58

Closed
v-shaal opened this issue Jun 9, 2018 · 9 comments
Closed

Remove service message #58

v-shaal opened this issue Jun 9, 2018 · 9 comments

Comments

@v-shaal
Copy link

v-shaal commented Jun 9, 2018

Can I remove the service message using the this
for eg

xyz joined the group
pqr left the group 

I want to remove the telegram message whenever user join or leave the group

@mukel
Copy link
Member

mukel commented Jun 9, 2018

A bot can remove messages https://stackoverflow.com/a/45285278/5457433 from groups and receive leave/join notifications ... not sure about service messages. It shouldn't be hard to set it up e.g. a bot that deletes all messages. I'll give it a shot.

@v-shaal
Copy link
Author

v-shaal commented Jun 9, 2018

php-telegram-bot/core#730 I am reffering to this , I am not sure about PHP though

@mukel
Copy link
Member

mukel commented Jun 9, 2018

Join/left messages are bundled in fields containing the users in Message.
Please try this, couldn't test it, but should work or be very close.

import info.mukel.telegrambot4s.api._
import info.mukel.telegrambot4s.methods._
import info.mukel.telegrambot4s.models._

/**
  * Remove join/left messages from groups.
  */
object GroupBot extends TelegramBot
  with Polling {
  lazy val token = "TOKEN"

  override def receiveMessage(msg: Message): Unit = {
    super.receiveMessage(msg)
    if (msg.newChatMembers.isDefined || msg.leftChatMember.isDefined)
      request(DeleteMessage(msg.source, msg.messageId))
  }
}

GroupBot.run()

@v-shaal
Copy link
Author

v-shaal commented Jun 10, 2018

Thanks It worked , but only for single group ,when I added the bot in two group it tarted throwing me this error .

ERROR info.mukel.telegrambot4s.clients.AkkaClient - Telegram API exception
info.mukel.telegrambot4s.api.TelegramApiException: Bad Request: message can't be deleted
	at info.mukel.telegrambot4s.clients.AkkaClient.$anonfun$apply$3(AkkaClient.scala:56)
	at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:302)
	at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
	at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:140)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.pollAndExecAll(ForkJoinPool.java:1021)
	at java.util.concurrent.ForkJoinPool$WorkQueue.execLocalTasks(ForkJoinPool.java:1046)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1058)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

@mukel
Copy link
Member

mukel commented Jun 10, 2018

It seems like a permission issue. The bot must be admin or have permission to delete messages.
https://core.telegram.org/bots/api#deletemessage

@mukel
Copy link
Member

mukel commented Jun 21, 2018

Any updates on this?

@v-shaal
Copy link
Author

v-shaal commented Jun 21, 2018

works perfect after giving permission.

@mukel mukel closed this as completed Jun 21, 2018
@sajadi1846
Copy link

hi . my bot delete the join and left service messages in my group but speed of deleting is so slow . when i add 50 person in one action with telegraph 50 service message apear in room and about 30 seconds for delete this 50 service messages with bot . my bot writen in php . see my code please . can you help me for solve this problem ? thanks

@sajadi1846
Copy link

@$newmember = $result->message->new_chat_member->id;
@$leftmember = $result->message->left_chat_member->id;
@$gpid = $result->message->chat->id;
@$messageid = $result->message->message_id;
$telegram = new telegram(TOKEN,HOST,USERNAME,PASSWORD,DBNAME);
if(!empty($newmember)|| !empty($leftmember)){
$telegram->deleteMessage($gpid,$messageid);
die();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants