[操作疑難] 有無師兄有用官方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