[操作疑难] 有无师兄有用官方whatsapp business api?

有无师兄有用官方whatsapp business api?
系唔系一定要经以下代理申请,
公司做物流的,想在每日送货前发一个whatsapp msg通知今日送货就系咁简单
(唔好问点解唔用sms)

https://www.facebook.com/busines ... p&languages=yue

唔洗经代理都得.   要系fb到验证返公司个br 果类野 .
好多资料去填.  仲要用埋信用卡.  唔俾用预付卡.  

不过用左咁耐1蚊都未扣过.  要超过佢个数量先会要俾钱.
不过如果自己唔想验证咁多野. 可能俾钱呢类代理买api 就实际得多.

TOP

咁我试下慢慢研究,d中间收费万万声

thanks

TOP

twilio果个系点样?

TOP

回覆 4# gn01119056

应该系 USD $0.005 for WhatsApp Session messages.

TOP

本帖最后由 杜龙 于 2023-12-24 18:09 编辑

疫情果时我整左个program fetch 强检大厦提示send message, 研究过whatsapp但要收钱, 最后用, telegram bot 做.
  1. from tabula import read_pdf, convert_into
  2. from tabulate import tabulate
  3. from PyPDF2 import PdfFileReader
  4. from commonfunction import *
  5. from telethon.sync import TelegramClient
  6. from telethon.tl.types import InputPeerUser, InputPeerChannel
  7. from telethon import TelegramClient, sync, events
  8. from os.path import exists

  9. # get your api_id, api_hash, token
  10. # from telegram as described above
  11. api_id = 'xx'
  12. api_hash = 'xxx'

  13. message = "Working..."


  14. #BuildingPdfURL = 'https://www.chp.gov.hk/files/pdf/ctn.pdf'


  15. class ClsCTNPDF:
  16.     def getDownloadPDFLocation(self):

  17.         return self.pdfldownloadpath

  18.     def __init__(self):
  19.         self.pdfldownloadpath = f'/config/workspaces/WorkspacePython/PDFScrape/pdf/restriction-testing{gettime()}.pdf'
  20.         self._building_pdf_url = Config().BuildingPdfURL
  21.         self.scheduleuser = AppDBRepo().getAllChatIDandSchedule()
  22.         logger.info('ini')

  23.     def downloadpdf(self):

  24.         if not exists(self.pdfldownloadpath):
  25.             command = ["wget", "-O",
  26.                        "{}".format(self.pdfldownloadpath), "{}".format(self._building_pdf_url)]
  27.             p = subprocess.Popen(command, stdout=subprocess.PIPE)
  28.             out, err = p.communicate()
  29.             logger.info("download out:{0}".format(out))
  30.             if err:
  31.                 logger.error(err)
  32.                 return False
  33.         return True

  34.     def ConvertPDFtoJson(self):

  35.         # reads table from pdf file
  36.         # tables  = read_pdf("abc.pdf",pages="all") #address of pdf file

  37.         jsonpath = f'/config/workspaces/WorkspacePython/PDFScrape/pdf/ctn{gettime()}.json'
  38.         convert_into(self.pdfldownloadpath, jsonpath,
  39.                      output_format="json", pages='all')

  40.         jsonfile = open(jsonpath)

  41.         self.data = json.load(jsonfile)
  42.         jsonfile.close()

  43.         return self.data

  44.     def ExtractBuildingList(self, maindistrict, subdistrict):
  45.         # if self.data is None:
  46.         maindistrict = maindistrict.replace("区", "")
  47.         subdistrict = subdistrict.replace("区", "")
  48.         logger.info("filter district main district:{0}, sub district:{1}".format(
  49.             maindistrict, subdistrict))
  50.         self.downloadpdf()
  51.         self.ConvertPDFtoJson()
  52.         building_list = []
  53.         for _d in self.data:
  54.             for _i in _d['data']:
  55.                 addr = _i[1]['text']

  56.                 if len(addr) > 0 and (maindistrict in addr or (subdistrict in addr)):
  57.                     building_list.append(addr.replace('\r', ' '))
  58.         self.building_list = building_list
  59.         return self.building_list

  60.     def getScheduleUserByChatID(self, chatid):
  61.         return self.getTblScheduleByChatID(chatid)[0].tblUser

  62.     def getTblScheduleByChatID(self, chatid):
  63.         return list(filter(lambda s: s.tblUser.chat_id == chatid, self.scheduleuser))

  64.     def sendTelegram(self, chatid):

  65.         objuser = self.getScheduleUserByChatID(chatid)
  66.         logger.info(
  67.             f"Handling telegram msg for USER:{objuser.user_name}/chat id:({objuser.chat_id})")

  68.         building_list = self.ExtractBuildingList(
  69.             objuser.main_district, objuser.sub_district)
  70.         if len(building_list) == 0:
  71.             logger.info("===No building in main district:{0} or subdistrict: {1}, will not post message====".format(
  72.                 objuser.main_district, objuser.user_name))
  73.         else:
  74.             _greeting = f"{objuser.user_name.upper()} 您好!\r\n根据香港衞生防护中心最新的公告({getLocalTime().strftime('%Y-%B-%d %H:%M:%S')})\r\n{self._building_pdf_url}\r\n\r\n在您登记的地区 :\r\n{objuser.main_district}/{objuser.sub_district}\r\n\r\n以下是需要进行新冠病毒强检的大厦名单 :\r\n"
  75.             _strBuildings = _greeting + ("\r\n".join(building_list))

  76.             logger.info(_strBuildings)
  77.             dopost = True

  78.             if dopost:
  79.                 SEND_URL = f'https://api.telegram.org/bot{Config().myToken}/sendMessage'
  80.                 requests.post(SEND_URL, json={
  81.                     'chat_id': chatid, 'text': _strBuildings})

  82.     def checkScheduleAndSendMsg(self):

  83.         logger.info('======Schedule job started at %s=========',
  84.                     getLocalTime())

  85.         chatids = set([int(s.tblUser.chat_id)
  86.                        for s in self.scheduleuser])
  87.         logger.info('chatids:{0}'.format(chatids))

  88.         for chatid in chatids:
  89.             sch = self.getTblScheduleByChatID(chatid)
  90.             objuser = sch[0].tblUser
  91.             LstSchedule = set(int(s.tblSchedule.schedule.strftime("%H"))
  92.                               for s in sch)
  93.             currenthour = getCurrentHour()
  94.             logger.info('Schedules for user {0}({1}):{2}, current hour:{3}'.format(
  95.                 objuser.user_name, chatid, LstSchedule, currenthour))

  96.             #logger.info("current hour: {0}".format(currenthour))

  97.             if (currenthour in LstSchedule):
  98.                 # if (currenthour in LstSchedule) or True:
  99.                 logger.info(
  100.                     '===========Current hour matches schedule============')
  101.                 self.sendTelegram(chatid)

  102.             else:
  103.                 logger.info("======Current hour not in user:{0}'s schedule=====".format(
  104.                     objuser.user_name))


  105. try:
  106.     ClsCTNPDF().checkScheduleAndSendMsg()
  107. except Exception as e:
  108.     logging.error('Error', exc_info=e)


  109. # your phone number
  110. phone = '+85212347897'
复制代码

TOP

开个帐号
https://developers.facebook.com/apps/?show_reminder=true

建立应用程式 (可能要公司BR上传)

Whatsapp -> API 设定  -> 建立号码.  
然后入信用卡.  

应该就可以玩用佢来收发 Whatsapp Message . (要自己搞埋个永久 api key 先唔会过期, google 找教学吧. )
  1. curl -i -X POST `
  2.   https://graph.facebook.com/v17.0/xxxxxxxxxxxxxxxxxxxxx/messages `
  3.   -H 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxx' `
  4.   -H 'Content-Type: application/json' `
  5.   -d '{ "messaging_product": "whatsapp", "to": "852xxxxxxxxxxxxxxxxxxxxx", "type": "template", "template": { "name": "hello_world", "language": { "code": "en_US" } } }'
复制代码
简单快捷.  

不过如果要玩埋收whatsapp message 就要配合好多野.

TOP

回覆 7# freefdhk

想问下,api endpoint 个 Phone-Number-ID 系唔系唔可以用佢试果个?
附件: 您需要登录才可以下载或查看附件。没有帐号?註册

TOP

回覆  freefdhk

想问下,api endpoint 个 Phone-Number-ID 系唔系唔可以用佢试果个?
...
gamezz 发表于 2023-12-27 16:53



测试号是可以传香港号码. 不过  要验证绑定 收信息的号码.  佢唔会比你拎来发广告.  

你在   Whatsapp -> 快速入门  > API 设定  
他的专用测试页面到试会比较简单.

TOP

回覆 9# freefdhk

Thanks. 这个真系清楚易明好多

TOP