我想要一种使用 Twilio 在 WhatsApp 上发送消息而不使用 Sandox 的方法你能帮我找到解决办法吗?

问题描述

我正在为一家非常小的公司制作一个警报应用程序,该公司没有 Facebook 商业页面,也没有我可以链接获取 WhatsApp API 的网站。您能否建议我使用 Twilio 但避免使用沙箱的替代方法。我已经做了这个项目大约一年了,但仍然无法成功解决问题。请帮我解决这个问题。 我还包括下面的代码片段以供参考。

import pandas as pd
from twilio.rest import Client 
import datetime
from datetime import date,timedelta

values=variables
df=pd.DataFrame(values)
df.drop(index=df.index[0],axis=0,inplace=True)
df.index = df.index-1



df['AMC_Start_Date']=df['AMC_Start_Date'].apply(lambda x:x.replace('/','-'))
df['AMC_End_Date']=df['AMC_End_Date'].apply(lambda x:x.replace('/','-'))


d1=date.today()
d1=pd.to_datetime(d1)


d2=df['AMC_Start_Date']
d2=pd.to_datetime(d2)
df['AMC_Start_Date'] = pd.to_datetime(df["AMC_Start_Date"])
df['AMC_End_Date'] = pd.to_datetime(df["AMC_End_Date"])


d2=df['AMC_Start_Date']
d3=df['AMC_End_Date']
t=d1-d2
s=d1-d3


account_sid=‘’
auth_token = 'a7' 
client = Client(account_sid,auth_token) 
def alert2(): 
  from datetime import date,timedelta 

  dt = date.today() - timedelta(856) 
  t2=df['AMC_Start_Date'] 
  t2=pd.to_datetime(t2,format='%Y-%m-%d') 
  t3=df['AMC_End_Date'] 
  t3=pd.to_datetime(t3,format='%Y-%m-%d') 
  dt1=date.today()-timedelta(989) 
  num=['whatsapp:+9198--------','whatsapp:+91900-------']
  i1=[i for i,e in enumerate(df['AMC_Start_Date']) if e == dt]
  i2=[i for i,e in enumerate(df['AMC_End_Date']) if e == dt1]
  NULL=[]
  for j in range(len(num)):
    if i1!=NULL and i2!=NULL:
      strings1 = [str(integer) for integer in i1]
      a_string = "". join(strings1)
      an_integer = int(a_string)
      a=df['Name_and_Address'][an_integer]
      strings2 = [str(integer) for integer in i2]
      a_string2 = "". join(strings2)
      an_integer2 = int(a_string2)
      b=df['Name_and_Address'][an_integer2]
      body='Servicing scheduled today for {}'.format(a) 
      message = client.messages.create( from_='whatsapp:+141--------',body=body,to=num[j])
      body='The service ends after two days for {}'.format(b) 
      message = client.messages.create( from_='whatsapp:+141-------',to=num[j])
    elif i1!=NULL:
      strings1 = [str(integer) for integer in i1]
      a_string = "". join(strings1)
      an_integer = int(a_string)
      a=df['Name_and_Address'][an_integer]
      body='Servicing scheduled today for {}'.format(a) 
      message = client.messages.create( from_='whatsapp:+141-------',to=num[j])
    elif i2!=NULL:
      strings2 = [str(integer) for integer in i2]
      a_string2 = "". join(strings2)
      an_integer2 = int(a_string2)
      b=df['Name_and_Address'][an_integer2]
      body='The service ends after two days for {}'.format(b) 
      message = client.messages.create( from_='whatsapp:+141------',to=num[j])
    else:
      body='There are no tasks scheduled for today' 
      message = client.messages.create( from_='whatsapp:+141-------',to=num[j])
alert2()
           

解决方法

这里是 Twilio 开发者布道者。

在生产中使用您自己的号码且没有沙盒限制的 WhatsApp API 的唯一方法是 follow the instructions in the documentation here。说明并未说明您需要 Facebook 主页或网站。你确实需要:

完成这些部分后,您应该start your application by filling in this form

如果没有 Facebook 商务管理平台帐户,您将无法使用 API。如果您无法创建其中一个,那么我不知道您可以使用 API 的方式。