Guest User

Untitled

a guest
Aug 3rd, 2022
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. from flask import Flask, request
  2. import requests
  3. import json
  4.  
  5. token = ''
  6. app = Flask(__name__)
  7.  
  8.  
  9. def send_message(chat_id, text):
  10. method = 'sendMessage'
  11. token = ''
  12. url = f"https://api.telegram.org/bot{token}/{method}"
  13. data = {"chat_id": chat_id, "text": text}
  14. requests.post(url, data=data)
  15.  
  16.  
  17. def send_pay_button(chat_id, text):
  18. method = "sendMessage"
  19. token = ''
  20. url = f"https://api.telegram.org/bot{token}/{method}"
  21.  
  22. data = {"chat_id": chat_id, "text": text, "reply_markup": json.dumps({"inline_keyboard": [
  23. [{
  24. 'text': 'one',
  25. 'callback_data': '1'
  26. },
  27. {'text': 'two',
  28. 'callback_data': '2'},
  29. ],
  30. [
  31. {'text': 'three',
  32. 'callback_data': '3'},
  33. ]],
  34. },
  35. )}
  36.  
  37. requests.post(url, data=data)
  38.  
  39.  
  40. @app.route('/', methods=["POST", "GET"])
  41. def index():
  42. chat_id = request.json['message']["chat"]["id"]
  43. send_pay_button(chat_id, text="Привет")
  44. return {"message": True}
  45.  
  46.  
  47.  
  48. if __name__ == '__main__':
  49. app.run()
  50.  
Advertisement
Add Comment
Please, Sign In to add comment