title: i want to send an auto reply to a new chat with whom i havent had a conversation earlier on Telegram
body: <p>I'm new to Python and Telethon.</p>
  <p>I've gone through the documentation of Telethon module.
  I would like to send auto reply to a new person if they send me a message on Telegram private message.</p>
  <p>I've found one (in <a href="https://gist.github.com/yi-jiayu/acc31fbad5a25f746430428ce4d62c28" rel="nofollow noreferrer">this gist</a>)
  which sends an autoreply to every incoming private chat. but i want to send a reply to new people only.</p>
  <p>please guide</p>
  <p>i want to check if user is present in the df below and send a reply accordingly.</p>
  <p>code to get list of dialog id's is as below:</p>
  <pre><code>import time
  from telethon import TelegramClient
  from telethon import events
  import pandas as pd
  
  api_id = 123456
  api_hash = 'enterownapihash'
  
  # fill in your own details here
  phone = '+111111111'
  session_file = 'username'  # use your username if unsure
  password = 'passwords'  # if you have two-step verification enabled
  
  client = TelegramClient(session_file, api_id, api_hash, sequential_updates=True)
  xyz = pd.DataFrame()
  z = pd.DataFrame()
  client.connect()
  client.start()
  
  for dialog in client.iter_dialogs():
      x = dialog.id
      y = dialog.title
      #print('{:&gt;14}: {}'.format(dialog.id, dialog.title))
      xyz['dialog id'] = [x]
      xyz['username'] = [y]
      z = pd.concat([z,xyz],ignore_index= True)
  print(xyz)
  print(z)
  </code></pre>
  <p><em><strong>EDIT:
  below is the code i've tried which hasnt worked.</strong></em></p>
  <pre><code>import time
  from telethon import TelegramClient
  from telethon import events
  import pandas as pd
  
  api_id = 123456
  api_hash = 'enterownapihash'
  
  # fill in your own details here
  phone = '+111111111'
  session_file = 'username'  # use your username if unsure
  password = 'passwords'  # if you have two-step verification enabled
  
  # content of the automatic reply
  message = &quot;Hello!&quot;
  
  client = TelegramClient(session_file, api_id, api_hash, sequential_updates=True)
  xyz = pd.DataFrame()
  z = pd.DataFrame()
  #client.connect()
  #client.start()
  
  for dialog in client.iter_dialogs():
      x = dialog.id
      y = dialog.title
      print('{:&gt;14}: {}'.format(dialog.id, dialog.title))
      xyz['x'] = [x]
      xyz['y'] = [y]
      z = pd.concat([z,xyz],ignore_index= True)
  
  if __name__ == '__main__':
  
      @client.on(events.NewMessage(incoming=True))
      async def handle_new_message(event):
          if event.is_private:  # only auto-reply to private chats
              from_ = await event.client.get_entity(event.from_id)  # this lookup will be cached by telethon
              if event.client.get_entity != z['x'].values:
                  if not from_.bot:  # don't auto-reply to bots
                      print(time.asctime(), '-', event.message)  # optionally log time and message
                      time.sleep(1)  # pause for 1 second to rate-limit automatic replies
                      await event.respond(message)
  
  
      client.start(phone, password)
      client.run_until_disconnected()
  </code></pre>